Skip to content
Permalink
Browse files

Fix PHPUnit getMock warnings in 3.next.

  • Loading branch information...
markstory committed Jun 16, 2016
1 parent 138f50f commit 618457e8a6c07c7c1247b4bee6f0acd6fc5bd270
@@ -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')
@@ -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'
@@ -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;
@@ -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));
@@ -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();
}
/**
@@ -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));
@@ -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')));
@@ -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);
@@ -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());
@@ -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));
@@ -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) {
@@ -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');
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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();
}
/**
@@ -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);
@@ -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]);
@@ -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);
@@ -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');
@@ -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');
@@ -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);
@@ -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);
@@ -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));
}
@@ -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);
@@ -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);
@@ -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]);
}

0 comments on commit 618457e

Please sign in to comment.
You can’t perform that action at this time.