Browse Source

Fix PHPUnit getMock warnings in 3.next.

Mark Story 9 years ago
parent
commit
618457e8a6

+ 9 - 3
tests/TestCase/Console/ShellTest.php

@@ -1145,10 +1145,16 @@ TEXT;
     {
         $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')

+ 8 - 14
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -165,13 +165,10 @@ class AuthComponentTest extends TestCase
      */
     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 @@ class AuthComponentTest extends TestCase
      */
     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;

+ 3 - 1
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -990,7 +990,9 @@ SQL;
     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));

+ 1 - 1
tests/TestCase/Database/Type/JsonTypeTest.php

@@ -33,7 +33,7 @@ class JsonTypeTest extends TestCase
     {
         parent::setUp();
         $this->type = Type::build('json');
-        $this->driver = $this->getMock('Cake\Database\Driver');
+        $this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
     }
 
     /**

+ 6 - 2
tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php

@@ -77,7 +77,9 @@ class ErrorHandlerMiddlewareTest extends TestCase
         $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 @@ class ErrorHandlerMiddlewareTest extends TestCase
         $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')));

+ 18 - 22
tests/TestCase/Http/ActionDispatcherTest.php

@@ -49,8 +49,8 @@ class ActionDispatcherTest extends TestCase
      */
     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 @@ class ActionDispatcherTest extends TestCase
         $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 @@ class ActionDispatcherTest extends TestCase
     {
         $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 @@ class ActionDispatcherTest extends TestCase
      */
     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 @@ class ActionDispatcherTest extends TestCase
      */
     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 @@ class ActionDispatcherTest extends TestCase
                 'action' => 'home',
             ]
         ]);
-        $response = $this->getMock('Cake\Network\Response');
+        $response = $this->getMockBuilder('Cake\Network\Response')->getMock();
         $this->dispatcher->dispatch($request, $response);
     }
 
@@ -291,7 +287,7 @@ class ActionDispatcherTest extends TestCase
                 'action' => 'index',
             ]
         ]);
-        $response = $this->getMock('Cake\Network\Response');
+        $response = $this->getMockBuilder('Cake\Network\Response')->getMock();
         $this->dispatcher->dispatch($request, $response);
     }
 
@@ -311,7 +307,7 @@ class ActionDispatcherTest extends TestCase
                 'action' => 'index',
             ]
         ]);
-        $response = $this->getMock('Cake\Network\Response');
+        $response = $this->getMockBuilder('Cake\Network\Response')->getMock();
         $this->dispatcher->dispatch($request, $response);
     }
 
@@ -336,7 +332,7 @@ class ActionDispatcherTest extends TestCase
                 'pass' => ['home'],
             ]
         ]);
-        $response = $this->getMock('Cake\Network\Response');
+        $response = $this->getMockBuilder('Cake\Network\Response')->getMock();
         $this->dispatcher->dispatch($request, $response);
     }
 

+ 1 - 1
tests/TestCase/Http/ControllerFactoryTest.php

@@ -35,7 +35,7 @@ class ControllerFactoryTest extends TestCase
         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();
     }
 
     /**

+ 6 - 2
tests/TestCase/Http/ResponseTransformerTest.php

@@ -198,7 +198,9 @@ class ResponseTransformerTest extends TestCase
      */
     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 @@ class ResponseTransformerTest extends TestCase
     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]);
 

+ 11 - 11
tests/TestCase/Http/RunnerTest.php

@@ -55,8 +55,8 @@ class RunnerTest extends TestCase
     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 @@ class RunnerTest extends TestCase
     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 @@ class RunnerTest extends TestCase
         $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 @@ class RunnerTest extends TestCase
     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 @@ class RunnerTest extends TestCase
     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);

+ 4 - 2
tests/TestCase/Http/ServerTest.php

@@ -57,7 +57,9 @@ class ServerTest extends TestCase
      */
     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 @@ class ServerTest extends TestCase
             ->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);

+ 3 - 1
tests/TestCase/ORM/EntityTest.php

@@ -714,7 +714,9 @@ class EntityTest extends TestCase
      */
     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);

+ 1 - 1
tests/TestCase/Shell/CacheShellTest.php

@@ -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]);
     }