Skip to content

Commit

Permalink
Fix PHPUnit getMock warnings in 3.next.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 16, 2016
1 parent 138f50f commit 618457e
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 61 deletions.
12 changes: 9 additions & 3 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -1145,10 +1145,16 @@ public function testRunCommandInvokeTask()
{
$parser = new ConsoleOptionParser('knife');
$parser->addSubcommand('slice');
$io = $this->getMock('Cake\Console\ConsoleIo');
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();

$shell = $this->getMock('Cake\Console\Shell', ['hasTask', 'getOptionParser'], [$io]);
$task = $this->getMock('Cake\Console\Shell', ['main', '_welcome'], [$io]);
$shell = $this->getMockBuilder('Cake\Console\Shell')
->setMethods(['hasTask', 'getOptionParser'])
->setConstructorArgs([$io])
->getMock();
$task = $this->getMockBuilder('Cake\Console\Shell')
->setMethods(['main', '_welcome'])
->setConstructorArgs([$io])
->getMock();

$shell->expects($this->once())
->method('getOptionParser')
Expand Down
22 changes: 8 additions & 14 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -165,13 +165,10 @@ public function testIdentify()
*/
public function testIdentifyArrayAccess()
{
$AuthLoginFormAuthenticate = $this->getMock(
'Cake\Controller\Component\Auth\FormAuthenticate',
['authenticate'],
[],
'',
false
);
$AuthLoginFormAuthenticate = $this->getMockBuilder('Cake\Controller\Component\Auth\FormAuthenticate')
->setMethods(['authenticate'])
->disableOriginalConstructor()
->getMock();
$this->Auth->authenticate = [
'AuthLoginForm' => [
'userModel' => 'AuthUsers'
Expand Down Expand Up @@ -315,13 +312,10 @@ public function testIsAuthorizedDelegation()
*/
public function testIsAuthorizedWithArrayObject()
{
$AuthMockOneAuthorize = $this->getMock(
'Cake\Controller\Component\BaseAuthorize',
['authorize'],
[],
'',
false
);
$AuthMockOneAuthorize = $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
->setMethods(['authorize'])
->disableOriginalConstructor()
->getMock();

$this->Auth->setAuthorizeObject(0, $AuthMockOneAuthorize);
$request = $this->Auth->request;
Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -990,7 +990,9 @@ public function testCreateSql()
public function testCreateSqlJson()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMock('Cake\Database\Connection', [], [], '', false);
$connection = $this->getMockBuilder('Cake\Database\Connection')
->disableOriginalConstructor()
->getMock();
$connection->expects($this->any())
->method('driver')
->will($this->returnValue($driver));
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Database/Type/JsonTypeTest.php
Expand Up @@ -33,7 +33,7 @@ public function setUp()
{
parent::setUp();
$this->type = Type::build('json');
$this->driver = $this->getMock('Cake\Database\Driver');
$this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
}

/**
Expand Down
Expand Up @@ -77,7 +77,9 @@ public function testRendererFactory()
$factory = function ($exception) {
$this->assertInstanceOf('LogicException', $exception);
$cakeResponse = new CakeResponse;
$mock = $this->getMock('StdClass', ['render']);
$mock = $this->getMockBuilder('StdClass')
->setMethods(['render'])
->getMock();
$mock->expects($this->once())
->method('render')
->will($this->returnValue($cakeResponse));
Expand Down Expand Up @@ -124,7 +126,9 @@ public function testHandleExceptionRenderingFails()
$response = new Response();

$factory = function ($exception) {
$mock = $this->getMock('StdClass', ['render']);
$mock = $this->getMockBuilder('StdClass')
->setMethods(['render'])
->getMock();
$mock->expects($this->once())
->method('render')
->will($this->throwException(new LogicException('Rendering failed')));
Expand Down
40 changes: 18 additions & 22 deletions tests/TestCase/Http/ActionDispatcherTest.php
Expand Up @@ -49,8 +49,8 @@ public function setUp()
*/
public function testConstructorArgs()
{
$factory = $this->getMock('Cake\Http\ControllerFactory');
$events = $this->getMock('Cake\Event\EventManager');
$factory = $this->getMockBuilder('Cake\Http\ControllerFactory')->getMock();
$events = $this->getMockBuilder('Cake\Event\EventManager')->getMock();
$dispatcher = new ActionDispatcher($factory, $events);

$this->assertAttributeSame($events, '_eventManager', $dispatcher);
Expand All @@ -69,10 +69,9 @@ public function testAddFilter()
$this->assertCount(1, $events->listeners('Dispatcher.beforeDispatch'));
$this->assertCount(1, $events->listeners('Dispatcher.afterDispatch'));

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

$this->assertCount(2, $this->dispatcher->getFilters());
Expand All @@ -89,10 +88,9 @@ public function testBeforeDispatchEventAbort()
{
$response = new Response();
$dispatcher = new ActionDispatcher();
$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 @@ -111,10 +109,9 @@ public function testBeforeDispatchEventAbort()
*/
public function testDispatchAfterDispatchEventModifyResponse()
{
$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch', 'afterDispatch']
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch', 'afterDispatch'])
->getMock();
$filter->expects($this->once())
->method('afterDispatch')
->will($this->returnCallback(function ($event) {
Expand Down Expand Up @@ -145,10 +142,9 @@ public function testDispatchAfterDispatchEventModifyResponse()
*/
public function testDispatchActionReturnResponseNoAfterDispatch()
{
$filter = $this->getMock(
'Cake\Routing\DispatcherFilter',
['beforeDispatch', 'afterDispatch']
);
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
->setMethods(['beforeDispatch', 'afterDispatch'])
->getMock();
$filter->expects($this->never())
->method('afterDispatch');

Expand Down Expand Up @@ -271,7 +267,7 @@ public function testMissingController()
'action' => 'home',
]
]);
$response = $this->getMock('Cake\Network\Response');
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
$this->dispatcher->dispatch($request, $response);
}

Expand All @@ -291,7 +287,7 @@ public function testMissingControllerInterface()
'action' => 'index',
]
]);
$response = $this->getMock('Cake\Network\Response');
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
$this->dispatcher->dispatch($request, $response);
}

Expand All @@ -311,7 +307,7 @@ public function testMissingControllerAbstract()
'action' => 'index',
]
]);
$response = $this->getMock('Cake\Network\Response');
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
$this->dispatcher->dispatch($request, $response);
}

Expand All @@ -336,7 +332,7 @@ public function testMissingControllerLowercase()
'pass' => ['home'],
]
]);
$response = $this->getMock('Cake\Network\Response');
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
$this->dispatcher->dispatch($request, $response);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/ControllerFactoryTest.php
Expand Up @@ -35,7 +35,7 @@ public function setUp()
parent::setUp();
Configure::write('App.namespace', 'TestApp');
$this->factory = new ControllerFactory();
$this->response = $this->getMock('Cake\Network\Response');
$this->response = $this->getMockBuilder('Cake\Network\Response')->getMock();
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/Http/ResponseTransformerTest.php
Expand Up @@ -198,7 +198,9 @@ public function testToPsrBodyCallable()
*/
public function testToPsrBodyFileResponse()
{
$cake = $this->getMock('Cake\Network\Response', ['_clearBuffer']);
$cake = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_clearBuffer'])
->getMock();
$cake->file(__FILE__, ['name' => 'some-file.php', 'download' => true]);

$result = ResponseTransformer::toPsr($cake);
Expand All @@ -225,7 +227,9 @@ public function testToPsrBodyFileResponse()
public function testToPsrBodyFileResponseFileRange()
{
$_SERVER['HTTP_RANGE'] = 'bytes=10-20';
$cake = $this->getMock('Cake\Network\Response', ['_clearBuffer']);
$cake = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_clearBuffer'])
->getMock();
$path = TEST_APP . 'webroot/css/cake.generic.css';
$cake->file($path, ['name' => 'test-asset.css', 'download' => true]);

Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Http/RunnerTest.php
Expand Up @@ -55,8 +55,8 @@ public function setUp()
public function testRunSingle()
{
$this->stack->push($this->ok);
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();

$runner = new Runner();
$result = $runner->run($this->stack, $req, $res);
Expand All @@ -71,14 +71,14 @@ public function testRunSingle()
public function testRunResponseReplace()
{
$one = function ($req, $res, $next) {
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
return $next($req, $res);
};
$this->stack->push($one);
$runner = new Runner();

$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
$result = $runner->run($this->stack, $req, $res);

$this->assertNotSame($res, $result, 'Response was not replaced');
Expand Down Expand Up @@ -108,8 +108,8 @@ public function testRunSequencing()
$this->stack->push($one)->push($two)->push($three);
$runner = new Runner();

$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
$result = $runner->run($this->stack, $req, $res);

$this->assertSame($res, $result, 'Response is not correct');
Expand All @@ -127,8 +127,8 @@ public function testRunSequencing()
public function testRunExceptionInMiddleware()
{
$this->stack->push($this->ok)->push($this->fail);
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();

$runner = new Runner();
$runner->run($this->stack, $req, $res);
Expand All @@ -142,8 +142,8 @@ public function testRunExceptionInMiddleware()
public function testRunNextNotCalled()
{
$this->stack->push($this->noNext);
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();

$runner = new Runner();
$result = $runner->run($this->stack, $req, $res);
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Http/ServerTest.php
Expand Up @@ -57,7 +57,9 @@ public function tearDown()
*/
public function testAppGetSet()
{
$app = $this->getMock('Cake\Http\BaseApplication', [], [$this->config]);
$app = $this->getMockBuilder('Cake\Http\BaseApplication')
->setConstructorArgs([$this->config])
->getMock();
$server = new Server($app);
$this->assertSame($app, $server->getApp($app));
}
Expand Down Expand Up @@ -160,7 +162,7 @@ public function testEmit()
->withHeader('X-First', 'first')
->withHeader('X-Second', 'second');

$emitter = $this->getMock('Zend\Diactoros\Response\EmitterInterface');
$emitter = $this->getMockBuilder('Zend\Diactoros\Response\EmitterInterface')->getMock();
$emitter->expects($this->once())
->method('emit')
->with($final);
Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/ORM/EntityTest.php
Expand Up @@ -714,7 +714,9 @@ public function testJsonSerialize()
*/
public function testJsonSerializeRecursive()
{
$phone = $this->getMock(Entity::class, ['jsonSerialize']);
$phone = $this->getMockBuilder(Entity::class)
->setMethods(['jsonSerialize'])
->getMock();
$phone->expects($this->once())->method('jsonSerialize')->will($this->returnValue('12345'));
$data = ['name' => 'James', 'age' => 20, 'phone' => $phone];
$entity = new Entity($data);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/CacheShellTest.php
Expand Up @@ -32,7 +32,7 @@ class CacheShellTest extends TestCase
public function setUp()
{
parent::setUp();
$this->io = $this->getMock('Cake\Console\ConsoleIo');
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
$this->shell = new CacheShell($this->io);
Cache::config('test', ['engine' => 'File', 'path' => TMP]);
}
Expand Down

0 comments on commit 618457e

Please sign in to comment.