Skip to content

Commit

Permalink
Remove use of TestCase::getMock() from "Routing" namepace tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 5, 2016
1 parent 07e390b commit 893358f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 41 deletions.
8 changes: 6 additions & 2 deletions tests/TestCase/Routing/DispatcherFactoryTest.php
Expand Up @@ -41,7 +41,9 @@ public function setUp()
*/
public function testAddFilter()
{
$mw = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch']);
$mw = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch'])
->getMock();
$result = DispatcherFactory::add($mw);
$this->assertSame($mw, $result);
}
Expand Down Expand Up @@ -89,7 +91,9 @@ public function testAddFilterWithOptions()
*/
public function testCreate()
{
$mw = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch']);
$mw = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch'])
->getMock();
DispatcherFactory::add($mw);
$result = DispatcherFactory::create();
$this->assertInstanceOf('Cake\Routing\Dispatcher', $result);
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Routing/DispatcherFilterTest.php
Expand Up @@ -179,7 +179,9 @@ public function testImplementedEventsMethodName()
$beforeEvent = new Event('Dispatcher.beforeDispatch', $this, compact('response', 'request'));
$afterEvent = new Event('Dispatcher.afterDispatch', $this, compact('response', 'request'));

$filter = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch', 'afterDispatch']);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch', 'afterDispatch'])
->getMock();
$filter->expects($this->at(0))
->method('beforeDispatch')
->with($beforeEvent);
Expand All @@ -204,11 +206,10 @@ public function testHandleAppliesFor()

$event = new Event('Dispatcher.beforeDispatch', $this, compact('response', 'request'));

$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch'],
[['for' => '/admin']]
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch'])
->setConstructorArgs([['for' => '/admin']])
->getMock();
$filter->expects($this->never())
->method('beforeDispatch');

Expand All @@ -231,11 +232,10 @@ public function testHandleAppliesWhen()
return false;
};

$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch'],
[['when' => $matcher]]
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch'])
->setConstructorArgs([['when' => $matcher]])
->getMock();
$filter->expects($this->never())
->method('beforeDispatch');

Expand Down
37 changes: 21 additions & 16 deletions tests/TestCase/Routing/DispatcherTest.php
Expand Up @@ -361,7 +361,9 @@ public function testDispatchActionReturnsResponse()
'pass' => []
]
]);
$response = $this->getMock('Cake\Network\Response', ['_sendHeader']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader'])
->getMock();

ob_start();
$this->dispatcher->dispatch($request, $response);
Expand Down Expand Up @@ -484,10 +486,9 @@ public function testDispatchBadName()
*/
public function testDispatcherFilter()
{
$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch', 'afterDispatch']
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch', 'afterDispatch'])
->getMock();

$filter->expects($this->at(0))
->method('beforeDispatch');
Expand All @@ -504,7 +505,9 @@ public function testDispatcherFilter()
'pass' => []
]
]);
$response = $this->getMock('Cake\Network\Response', ['send']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['send'])
->getMock();
$this->dispatcher->dispatch($request, $response);
}

Expand All @@ -515,14 +518,15 @@ public function testDispatcherFilter()
*/
public function testBeforeDispatchAbortDispatch()
{
$response = $this->getMock('Cake\Network\Response', ['send']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['send'])
->getMock();
$response->expects($this->once())
->method('send');

$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch', 'afterDispatch']
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch', 'afterDispatch'])
->getMock();
$filter->expects($this->once())
->method('beforeDispatch')
->will($this->returnValue($response));
Expand All @@ -543,14 +547,15 @@ public function testBeforeDispatchAbortDispatch()
*/
public function testAfterDispatchReplaceResponse()
{
$response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'send']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader', 'send'])
->getMock();
$response->expects($this->once())
->method('send');

$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch', 'afterDispatch']
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch', 'afterDispatch'])
->getMock();

$filter->expects($this->once())
->method('afterDispatch')
Expand Down
23 changes: 16 additions & 7 deletions tests/TestCase/Routing/Filter/AssetFilterTest.php
Expand Up @@ -13,7 +13,6 @@
*/
namespace Cake\Test\TestCase\Routing\Filter;

use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Event\Event;
use Cake\Network\Request;
Expand Down Expand Up @@ -62,7 +61,9 @@ public function testNotModified()
$time = filemtime(Plugin::path('TestTheme') . 'webroot/img/cake.power.gif');
$time = new \DateTime('@' . $time);

$response = $this->getMock('Cake\Network\Response', ['send', 'checkNotModified']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['send', 'checkNotModified'])
->getMock();
$request = new Request('test_theme/img/cake.power.gif');

$response->expects($this->once())->method('checkNotModified')
Expand All @@ -76,7 +77,9 @@ public function testNotModified()
$this->assertEquals(200, $response->statusCode());
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());

$response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'checkNotModified', 'send']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader', 'checkNotModified', 'send'])
->getMock();
$request = new Request('test_theme/img/cake.power.gif');

$response->expects($this->once())->method('checkNotModified')
Expand All @@ -99,7 +102,9 @@ public function test404OnDoubleSlash()
{
$filter = new AssetFilter();

$response = $this->getMock('Response', ['_sendHeader']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader'])
->getMock();
$request = new Request('//index.php');
$event = new Event('Dispatcher.beforeRequest', $this, compact('request', 'response'));

Expand All @@ -110,15 +115,17 @@ public function test404OnDoubleSlash()
/**
* Test that 404's are returned when .. is in the URL
*
* @return voi
* @return void
* @triggers Dispatcher.beforeRequest $this, compact('request', 'response')
* @triggers Dispatcher.beforeRequest $this, compact('request', 'response')
*/
public function test404OnDoubleDot()
{
$filter = new AssetFilter();

$response = $this->getMock('Response', ['_sendHeader']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader'])
->getMock();
$request = new Request('test_theme/../webroot/css/test_asset.css');
$event = new Event('Dispatcher.beforeRequest', $this, compact('request', 'response'));

Expand Down Expand Up @@ -232,7 +239,9 @@ public function testAsset($url, $file)
Plugin::load(['Company/TestPluginThree', 'TestPlugin', 'PluginJs']);

$filter = new AssetFilter();
$response = $this->getMock('Cake\Network\Response', ['_sendHeader']);
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader'])
->getMock();
$request = new Request($url);
$event = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response'));

Expand Down
9 changes: 4 additions & 5 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -2770,11 +2770,10 @@ public function testUrlFullUrlReturnFromRoute()
{
$url = 'http://example.com/posts/view/1';

$route = $this->getMock(
'Cake\Routing\Route\Route',
['match'],
['/:controller/:action/*']
);
$route = $this->getMockBuilder('Cake\Routing\Route\Route')
->setMethods(['match'])
->setConstructorArgs(['/:controller/:action/*'])
->getMock();
$route->expects($this->any())
->method('match')
->will($this->returnValue($url));
Expand Down

0 comments on commit 893358f

Please sign in to comment.