Browse Source

Remove use of TestCase::getMock() from "Controller" namepace tests.

ADmad 9 years ago
parent
commit
d00d7fdfe0

+ 72 - 95
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -20,7 +20,6 @@ use Cake\Event\Event;
 use Cake\Event\EventManager;
 use Cake\Network\Request;
 use Cake\Network\Response;
-use Cake\Network\Session;
 use Cake\ORM\TableRegistry;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
@@ -66,7 +65,9 @@ class AuthComponentTest extends TestCase
         });
 
         $request = new Request();
-        $response = $this->getMock('Cake\Network\Response', ['stop']);
+        $response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['stop'])
+            ->getMock();
 
         $this->Controller = new AuthTestController($request, $response);
         $this->Auth = new TestAuthComponent($this->Controller->components());
@@ -123,13 +124,10 @@ class AuthComponentTest extends TestCase
      */
     public function testIdentify()
     {
-        $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'
@@ -231,27 +229,18 @@ class AuthComponentTest extends TestCase
      */
     public function testIsAuthorizedDelegation()
     {
-        $AuthMockOneAuthorize = $this->getMock(
-            'Cake\Controller\Component\BaseAuthorize',
-            ['authorize'],
-            [],
-            '',
-            false
-        );
-        $AuthMockTwoAuthorize = $this->getMock(
-            'Cake\Controller\Component\Auth\BaseAuthorize',
-            ['authorize'],
-            [],
-            '',
-            false
-        );
-        $AuthMockThreeAuthorize = $this->getMock(
-            'Cake\Controller\Component\Auth\BaseAuthorize',
-            ['authorize'],
-            [],
-            '',
-            false
-        );
+        $AuthMockOneAuthorize = $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
+            ->setMethods(['authorize'])
+            ->disableOriginalConstructor()
+            ->getMock();
+        $AuthMockTwoAuthorize = $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
+            ->setMethods(['authorize'])
+            ->disableOriginalConstructor()
+            ->getMock();
+        $AuthMockThreeAuthorize = $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
+            ->setMethods(['authorize'])
+            ->disableOriginalConstructor()
+            ->getMock();
 
         $this->Auth->setAuthorizeObject(0, $AuthMockOneAuthorize);
         $this->Auth->setAuthorizeObject(1, $AuthMockTwoAuthorize);
@@ -282,13 +271,10 @@ class AuthComponentTest extends TestCase
      */
     public function testIsAuthorizedUsingUserInSession()
     {
-        $AuthMockFourAuthorize = $this->getMock(
-            'Cake\Controller\Component\Auth\BaseAuthorize',
-            ['authorize'],
-            [],
-            '',
-            false
-        );
+        $AuthMockFourAuthorize = $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
+            ->setMethods(['authorize'])
+            ->disableOriginalConstructor()
+            ->getMock();
         $this->Auth->config('authorize', ['AuthMockFour']);
         $this->Auth->setAuthorizeObject(0, $AuthMockFourAuthorize);
 
@@ -676,13 +662,11 @@ class AuthComponentTest extends TestCase
 
         $this->Auth->session->write('Auth.User.id', '1');
         $this->Auth->config('authenticate', ['Form']);
-        $this->getMock(
-            'Cake\Controller\Component\Auth\BaseAuthorize',
-            ['authorize'],
-            [],
-            'NoLoginRedirectMockAuthorize',
-            false
-        );
+        $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
+            ->setMethods(['authorize'])
+            ->disableOriginalConstructor()
+            ->setMockClassName('NoLoginRedirectMockAuthorize')
+            ->getMock();
         $this->Auth->config('authorize', ['NoLoginRedirectMockAuthorize']);
         $this->Auth->config('loginAction', ['controller' => 'auth_test', 'action' => 'login']);
 
@@ -718,11 +702,10 @@ class AuthComponentTest extends TestCase
         ]);
 
         $response = new Response();
-        $Controller = $this->getMock(
-            'Cake\Controller\Controller',
-            ['on', 'redirect'],
-            [$request, $response]
-        );
+        $Controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['on', 'redirect'])
+            ->setConstructorArgs([$request, $response])
+            ->getMock();
         $event = new Event('Controller.startup', $Controller);
 
         // Should not contain basedir when redirect is called.
@@ -742,11 +725,10 @@ class AuthComponentTest extends TestCase
     public function testRedirectToUnauthorizedRedirect()
     {
         $url = '/party/on';
-        $this->Auth->Flash = $this->getMock(
-            'Cake\Controller\Component\FlashComponent',
-            ['set'],
-            [$this->Controller->components()]
-        );
+        $this->Auth->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent')
+            ->setMethods(['set'])
+            ->setConstructorArgs([$this->Controller->components()])
+            ->getMock();
         $this->Auth->request = $request = new Request([
             'url' => $url,
             'session' => $this->Auth->session
@@ -759,11 +741,10 @@ class AuthComponentTest extends TestCase
         $this->Auth->config('unauthorizedRedirect', $expected);
 
         $response = new Response();
-        $Controller = $this->getMock(
-            'Cake\Controller\Controller',
-            ['on', 'redirect'],
-            [$request, $response]
-        );
+        $Controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['on', 'redirect'])
+            ->setConstructorArgs([$request, $response])
+            ->getMock();
 
         $Controller->expects($this->once())
             ->method('redirect')
@@ -785,11 +766,10 @@ class AuthComponentTest extends TestCase
     public function testRedirectToUnauthorizedRedirectLoginAction()
     {
         $url = '/party/on';
-        $this->Auth->Flash = $this->getMock(
-            'Cake\Controller\Component\FlashComponent',
-            ['set'],
-            [$this->Controller->components()]
-        );
+        $this->Auth->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent')
+            ->setMethods(['set'])
+            ->setConstructorArgs([$this->Controller->components()])
+            ->getMock();
         $this->Auth->request = $request = new Request([
             'url' => $url,
             'session' => $this->Auth->session
@@ -802,11 +782,10 @@ class AuthComponentTest extends TestCase
         $this->Auth->config('loginAction', '/users/login');
 
         $response = new Response();
-        $Controller = $this->getMock(
-            'Cake\Controller\Controller',
-            ['on', 'redirect'],
-            [$request, $response]
-        );
+        $Controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['on', 'redirect'])
+            ->setConstructorArgs([$request, $response])
+            ->getMock();
 
         // Uses referrer instead of loginAction.
         $Controller->expects($this->once())
@@ -826,10 +805,9 @@ class AuthComponentTest extends TestCase
     public function testRedirectToUnauthorizedRedirectSuppressedAuthError()
     {
         $url = '/party/on';
-        $this->Auth->session = $this->getMock(
-            'Cake\Network\Session',
-            ['flash']
-        );
+        $this->Auth->session = $this->getMockBuilder('Cake\Network\Session')
+            ->setMethods(['flash'])
+            ->getMock();
         $this->Auth->request = $Request = new Request($url);
         $this->Auth->request->addParams(Router::parse($url));
         $this->Auth->config('authorize', ['Controller']);
@@ -839,11 +817,10 @@ class AuthComponentTest extends TestCase
         $this->Auth->config('authError', false);
 
         $Response = new Response();
-        $Controller = $this->getMock(
-            'Cake\Controller\Controller',
-            ['on', 'redirect'],
-            [$Request, $Response]
-        );
+        $Controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['on', 'redirect'])
+            ->setConstructorArgs([$Request, $Response])
+            ->getMock();
 
         $Controller->expects($this->once())
             ->method('redirect')
@@ -875,11 +852,10 @@ class AuthComponentTest extends TestCase
         $this->Auth->setUser(['username' => 'baker', 'password' => 'cake']);
 
         $response = new Response();
-        $Controller = $this->getMock(
-            'Cake\Controller\Controller',
-            ['on', 'redirect'],
-            [$request, $response]
-        );
+        $Controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['on', 'redirect'])
+            ->setConstructorArgs([$request, $response])
+            ->getMock();
 
         $event = new Event('Controller.startup', $Controller);
         $this->Auth->startup($event);
@@ -894,7 +870,9 @@ class AuthComponentTest extends TestCase
     public function testNoRedirectOnLoginAction()
     {
         $event = new Event('Controller.startup', $this->Controller);
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->methods = ['login'];
 
         $url = '/AuthTest/login';
@@ -1199,11 +1177,10 @@ class AuthComponentTest extends TestCase
      */
     public function testSetUser()
     {
-        $storage = $this->getMock(
-            'Cake\Auth\Storage\SessionStorage',
-            ['write'],
-            [$this->Auth->request, $this->Auth->response]
-        );
+        $storage = $this->getMockBuilder('Cake\Auth\Storage\SessionStorage')
+            ->setMethods(['write'])
+            ->setConstructorArgs([$this->Auth->request, $this->Auth->response])
+            ->getMock();
         $this->Auth->storage($storage);
 
         $user = ['username' => 'mark', 'role' => 'admin'];
@@ -1243,11 +1220,9 @@ class AuthComponentTest extends TestCase
      */
     public function testFlashSettings()
     {
-        $this->Auth->Flash = $this->getMock(
-            'Cake\Controller\Component\FlashComponent',
-            [],
-            [$this->Controller->components()]
-        );
+        $this->Auth->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent')
+            ->setConstructorArgs([$this->Controller->components()])
+            ->getMock();
         $this->Controller->request->params['action'] = 'add';
         $this->Auth->startup(new Event('Controller.startup', $this->Controller));
 
@@ -1450,7 +1425,9 @@ class AuthComponentTest extends TestCase
      */
     public function testStatelessFollowedByStatefulAuth()
     {
-        $this->Auth->response = $this->getMock('Cake\Network\Response', ['stop', 'statusCode', 'send']);
+        $this->Auth->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['stop', 'statusCode', 'send'])
+            ->getMock();
         $event = new Event('Controller.startup', $this->Controller);
         $this->Auth->authenticate = ['Basic', 'Form'];
         $this->Controller->request['action'] = 'add';

+ 4 - 5
tests/TestCase/Controller/Component/CookieComponentTest.php

@@ -36,11 +36,10 @@ class CookieComponentTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $controller = $this->getMock(
-            'Cake\Controller\Controller',
-            ['redirect'],
-            [new Request(), new Response()]
-        );
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->setConstructorArgs([new Request(), new Response()])
+            ->getMock();
         $controller->loadComponent('Cookie');
         $this->Controller = $controller;
         $this->Cookie = $controller->Cookie;

+ 36 - 12
tests/TestCase/Controller/Component/CsrfComponentTest.php

@@ -37,7 +37,9 @@ class CsrfComponentTest extends TestCase
     {
         parent::setUp();
 
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $this->registry = new ComponentRegistry($controller);
         $this->component = new CsrfComponent($this->registry);
     }
@@ -61,7 +63,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testSettingCookie()
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => ['REQUEST_METHOD' => 'GET'],
             'webroot' => '/dir/',
@@ -102,7 +106,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testSafeMethodNoCsrfRequired($method)
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => $method,
@@ -138,7 +144,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testValidTokenInHeader($method)
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => $method,
@@ -164,7 +172,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testInvalidTokenInHeader($method)
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => $method,
@@ -188,7 +198,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testValidTokenRequestData($method)
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => $method,
@@ -213,7 +225,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testInvalidTokenRequestData($method)
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => $method,
@@ -235,7 +249,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testInvalidTokenRequestDataMissing()
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => 'POST',
@@ -258,7 +274,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testInvalidTokenMissingCookie($method)
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => [
                 'REQUEST_METHOD' => $method
@@ -280,7 +298,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testCsrfValidationSkipsRequestAction()
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => ['REQUEST_METHOD' => 'POST'],
             'params' => ['requested' => 1],
@@ -303,7 +323,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testConfigurationCookieCreate()
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => ['REQUEST_METHOD' => 'GET'],
             'webroot' => '/dir/'
@@ -338,7 +360,9 @@ class CsrfComponentTest extends TestCase
      */
     public function testConfigurationValidate()
     {
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $controller->request = new Request([
             'environment' => ['REQUEST_METHOD' => 'POST'],
             'cookies' => ['csrfToken' => 'nope', 'token' => 'yes'],

+ 13 - 10
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -73,7 +73,9 @@ class PaginatorComponentTest extends TestCase
         $registry = new ComponentRegistry($controller);
         $this->Paginator = new PaginatorComponent($registry, []);
 
-        $this->Post = $this->getMock('Cake\ORM\Table', [], [], '', false);
+        $this->Post = $this->getMockBuilder('Cake\ORM\Table')
+            ->disableOriginalConstructor()
+            ->getMock();
     }
 
     /**
@@ -1019,14 +1021,13 @@ class PaginatorComponentTest extends TestCase
      * Helper method for making mocks.
      *
      * @param array $methods
-     * @return Table
+     * @return \Cake\ORM\Table
      */
     protected function _getMockPosts($methods = [])
     {
-        return $this->getMock(
-            'TestApp\Model\Table\PaginatorPostsTable',
-            $methods,
-            [[
+        return $this->getMockBuilder('TestApp\Model\Table\PaginatorPostsTable')
+            ->setMethods($methods)
+            ->setConstructorArgs([[
                 'connection' => ConnectionManager::get('test'),
                 'alias' => 'PaginatorPosts',
                 'schema' => [
@@ -1037,14 +1038,14 @@ class PaginatorComponentTest extends TestCase
                     'published' => ['type' => 'string', 'length' => 1, 'default' => 'N'],
                     '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
                 ]
-            ]]
-        );
+            ]])
+            ->getMock();
     }
 
     /**
      * Helper method for mocking queries.
      *
-     * @return Query
+     * @return \Cake\ORM\Query
      */
     protected function _getMockFindQuery($table = null)
     {
@@ -1053,7 +1054,9 @@ class PaginatorComponentTest extends TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
-        $results = $this->getMock('Cake\ORM\ResultSet', [], [], '', false);
+        $results = $this->getMockBuilder('Cake\ORM\ResultSet')
+            ->disableOriginalConstructor()
+            ->getMock();
         $query->expects($this->any())
             ->method('count')
             ->will($this->returnValue(2));

+ 88 - 33
tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

@@ -66,7 +66,9 @@ class RequestHandlerComponentTest extends TestCase
     protected function _init()
     {
         $request = new Request('controller_posts/index');
-        $response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'stop']);
+        $response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['_sendHeader', 'stop'])
+            ->getMock();
         $this->Controller = new RequestHandlerTestController($request, $response);
         $this->RequestHandler = $this->Controller->components()->load('RequestHandler');
         $this->request = $request;
@@ -101,7 +103,9 @@ class RequestHandlerComponentTest extends TestCase
         $config = [
             'viewClassMap' => ['json' => 'MyPlugin.MyJson']
         ];
-        $controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
+        $controller = $this->getMockBuilder('Cake\Controller\Controller')
+            ->setMethods(['redirect'])
+            ->getMock();
         $collection = new ComponentRegistry($controller);
         $requestHandler = new RequestHandlerComponent($collection, $config);
         $this->assertEquals(['json' => 'MyPlugin.MyJson'], $requestHandler->config('viewClassMap'));
@@ -293,7 +297,9 @@ class RequestHandlerComponentTest extends TestCase
         $extensions = Router::extensions();
         Router::extensions('xml', false);
 
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['accepts']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['accepts'])
+            ->getMock();
         $this->Controller->request->expects($this->any())
             ->method('accepts')
             ->will($this->returnValue(['application/json']));
@@ -472,7 +478,9 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.beforeRender', $this->Controller);
         $_SERVER['REQUEST_METHOD'] = 'PUT';
         $_SERVER['CONTENT_TYPE'] = 'application/xml';
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['_readInput']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['_readInput'])
+            ->getMock();
         $this->RequestHandler->beforeRender($event);
         $this->assertTrue(is_array($this->Controller->request->data));
         $this->assertFalse(is_object($this->Controller->request->data));
@@ -489,7 +497,9 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.startup', $this->Controller);
         $_SERVER['REQUEST_METHOD'] = 'PUT';
         $_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['_readInput']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['_readInput'])
+            ->getMock();
         $this->RequestHandler->startup($event);
         $this->assertTrue(is_array($this->Controller->request->data));
         $this->assertFalse(is_object($this->Controller->request->data));
@@ -503,7 +513,9 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testStartupProcessData()
     {
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['_readInput']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['_readInput'])
+            ->getMock();
         $this->Controller->request->expects($this->at(0))
             ->method('_readInput')
             ->will($this->returnValue(''));
@@ -536,7 +548,9 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testStartupIgnoreFileAsXml()
     {
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['_readInput']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['_readInput'])
+            ->getMock();
         $this->Controller->request->expects($this->any())
             ->method('_readInput')
             ->will($this->returnValue('/dev/random'));
@@ -558,7 +572,9 @@ class RequestHandlerComponentTest extends TestCase
     public function testStartupCustomTypeProcess()
     {
         $restore = error_reporting(E_ALL & ~E_USER_DEPRECATED);
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['_readInput']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['_readInput'])
+            ->getMock();
         $this->Controller->request->expects($this->once())
             ->method('_readInput')
             ->will($this->returnValue('"A","csv","string"'));
@@ -631,12 +647,16 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testRenderAsWithAttachment()
     {
-        $this->RequestHandler->request = $this->getMock('Cake\Network\Request', ['parseAccept']);
+        $this->RequestHandler->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['parseAccept'])
+            ->getMock();
         $this->RequestHandler->request->expects($this->any())
             ->method('parseAccept')
             ->will($this->returnValue(['1.0' => ['application/xml']]));
 
-        $this->RequestHandler->response = $this->getMock('Cake\Network\Response', ['type', 'download', 'charset']);
+        $this->RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['type', 'download', 'charset'])
+            ->getMock();
         $this->RequestHandler->response->expects($this->at(0))
             ->method('type')
             ->with('application/xml');
@@ -659,7 +679,9 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testRespondAs()
     {
-        $this->RequestHandler->response = $this->getMock('Cake\Network\Response', ['type']);
+        $this->RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['type'])
+            ->getMock();
         $this->RequestHandler->response->expects($this->at(0))->method('type')
             ->with('application/json');
         $this->RequestHandler->response->expects($this->at(1))->method('type')
@@ -678,13 +700,16 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testRespondAsWithAttachment()
     {
-        $this->RequestHandler = $this->getMock(
-            'Cake\Controller\Component\RequestHandlerComponent',
-            ['_header'],
-            [$this->Controller->components()]
-        );
-        $this->RequestHandler->response = $this->getMock('Cake\Network\Response', ['type', 'download']);
-        $this->RequestHandler->request = $this->getMock('Cake\Network\Request', ['parseAccept']);
+        $this->RequestHandler = $this->getMockBuilder('Cake\Controller\Component\RequestHandlerComponent')
+            ->setMethods(['_header'])
+            ->setConstructorArgs([$this->Controller->components()])
+            ->getMock();
+        $this->RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['type', 'download'])
+            ->getMock();
+        $this->RequestHandler->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['parseAccept'])
+            ->getMock();
 
         $this->RequestHandler->request->expects($this->once())
             ->method('parseAccept')
@@ -794,7 +819,9 @@ class RequestHandlerComponentTest extends TestCase
      */
     public function testMobileDeviceDetection()
     {
-        $request = $this->getMock('Cake\Network\Request', ['is']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['is'])
+            ->getMock();
         $request->expects($this->once())->method('is')
             ->with('mobile')
             ->will($this->returnValue(true));
@@ -885,8 +912,12 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.beforeRedirect', $this->Controller);
 
         $this->Controller->RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['is']);
-        $this->Controller->response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'stop']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['is'])
+            ->getMock();
+        $this->Controller->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['_sendHeader', 'stop'])
+            ->getMock();
         $this->Controller->RequestHandler->request = $this->Controller->request;
         $this->Controller->RequestHandler->response = $this->Controller->response;
         $this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
@@ -912,8 +943,12 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.beforeRedirect', $this->Controller);
 
         $this->Controller->RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['is']);
-        $this->Controller->response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'stop']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['is'])
+            ->getMock();
+        $this->Controller->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['_sendHeader', 'stop'])
+            ->getMock();
         $this->Controller->RequestHandler->request = $this->Controller->request;
         $this->Controller->RequestHandler->response = $this->Controller->response;
         $this->Controller->request->expects($this->any())
@@ -951,8 +986,12 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.beforeRedirect', $this->Controller);
 
         $this->Controller->RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['is']);
-        $this->Controller->response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'stop']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['is'])
+            ->getMock();
+        $this->Controller->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['_sendHeader', 'stop'])
+            ->getMock();
         $this->Controller->RequestHandler->request = $this->Controller->request;
         $this->Controller->RequestHandler->response = $this->Controller->response;
         $this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
@@ -984,8 +1023,12 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.beforeRedirect', $this->Controller);
 
         $this->Controller->RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['is']);
-        $this->Controller->response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'stop']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['is'])
+            ->getMock();
+        $this->Controller->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['_sendHeader', 'stop'])
+            ->getMock();
         $this->Controller->response->statusCode(302);
         $this->Controller->RequestHandler->request = $this->Controller->request;
         $this->Controller->RequestHandler->response = $this->Controller->response;
@@ -1014,8 +1057,12 @@ class RequestHandlerComponentTest extends TestCase
         $event = new Event('Controller.beforeRedirect', $this->Controller);
 
         $this->Controller->RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $this->Controller->request = $this->getMock('Cake\Network\Request', ['is']);
-        $this->Controller->response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'stop']);
+        $this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['is'])
+            ->getMock();
+        $this->Controller->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['_sendHeader', 'stop'])
+            ->getMock();
         $this->Controller->RequestHandler->request = $this->Controller->request;
         $this->Controller->RequestHandler->response = $this->Controller->response;
         $this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
@@ -1087,7 +1134,9 @@ class RequestHandlerComponentTest extends TestCase
         $_SERVER['HTTP_IF_NONE_MATCH'] = '*';
         $event = new Event('Controller.beforeRender', $this->Controller);
         $RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $RequestHandler->response = $this->getMock('Cake\Network\Response', ['notModified', 'stop']);
+        $RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['notModified', 'stop'])
+            ->getMock();
         $RequestHandler->response->etag('something');
         $RequestHandler->response->expects($this->once())->method('notModified');
         $this->assertFalse($RequestHandler->beforeRender($event));
@@ -1104,7 +1153,9 @@ class RequestHandlerComponentTest extends TestCase
         $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"';
         $event = new Event('Controller.beforeRender');
         $RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $RequestHandler->response = $this->getMock('Cake\Network\Response', ['notModified', 'stop']);
+        $RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['notModified', 'stop'])
+            ->getMock();
         $RequestHandler->response->etag('something', true);
         $RequestHandler->response->expects($this->once())->method('notModified');
         $this->assertFalse($RequestHandler->beforeRender($event));
@@ -1122,7 +1173,9 @@ class RequestHandlerComponentTest extends TestCase
         $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00';
         $event = new Event('Controller.beforeRender', $this->Controller);
         $RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $RequestHandler->response = $this->getMock('Cake\Network\Response', ['notModified', 'stop']);
+        $RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['notModified', 'stop'])
+            ->getMock();
         $RequestHandler->response->etag('something', true);
         $RequestHandler->response->modified('2012-01-01 00:00:00');
         $RequestHandler->response->expects($this->once())->method('notModified');
@@ -1139,7 +1192,9 @@ class RequestHandlerComponentTest extends TestCase
     {
         $event = new Event('Controller.beforeRender', $this->Controller);
         $RequestHandler = new RequestHandlerComponent($this->Controller->components());
-        $RequestHandler->response = $this->getMock('Cake\Network\Response', ['notModified', 'stop']);
+        $RequestHandler->response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['notModified', 'stop'])
+            ->getMock();
         $RequestHandler->response->expects($this->never())->method('notModified');
         $this->assertNull($RequestHandler->beforeRender($event));
     }

+ 7 - 3
tests/TestCase/Controller/Component/SecurityComponentTest.php

@@ -19,7 +19,6 @@ use Cake\Controller\Controller;
 use Cake\Controller\Exception\SecurityException;
 use Cake\Core\Configure;
 use Cake\Event\Event;
-use Cake\Network\Exception\BadRequestException;
 use Cake\Network\Request;
 use Cake\Network\Session;
 use Cake\TestSuite\TestCase;
@@ -153,7 +152,10 @@ class SecurityComponentTest extends TestCase
         parent::setUp();
 
         $session = new Session();
-        $request = $this->getMock('Cake\Network\Request', ['here'], ['posts/index']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['here'])
+            ->setConstructorArgs(['posts/index'])
+            ->getMock();
         $request->addParams(['controller' => 'posts', 'action' => 'index']);
         $request->session($session);
         $request->expects($this->any())
@@ -1303,7 +1305,9 @@ class SecurityComponentTest extends TestCase
         ];
         $this->assertTrue($this->validatePost());
 
-        $request = $this->getMock('Cake\Network\Request', ['here']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['here'])
+            ->getMock();
         $request->expects($this->at(0))
             ->method('here')
             ->will($this->returnValue('/posts/index?page=1'));

+ 30 - 13
tests/TestCase/Controller/ControllerTest.php

@@ -23,7 +23,6 @@ use Cake\Network\Request;
 use Cake\Network\Response;
 use Cake\ORM\TableRegistry;
 use Cake\Routing\Router;
-use Cake\TestSuite\Fixture\TestModel;
 use Cake\TestSuite\TestCase;
 use TestApp\Controller\Admin\PostsController;
 use TestPlugin\Controller\TestPluginController;
@@ -509,7 +508,9 @@ class ControllerTest extends TestCase
      */
     public function testRedirectBeforeRedirectModifyingStatusCode()
     {
-        $Response = $this->getMock('Cake\Network\Response', ['stop']);
+        $Response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['stop'])
+            ->getMock();
         $Controller = new Controller(null, $Response);
 
         $Controller->eventManager()->attach(function ($event, $url, $response) {
@@ -524,7 +525,9 @@ class ControllerTest extends TestCase
 
     public function testRedirectBeforeRedirectListenerReturnResponse()
     {
-        $Response = $this->getMock('Cake\Network\Response', ['stop', 'header', 'statusCode']);
+        $Response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['stop', 'header', 'statusCode'])
+            ->getMock();
         $Controller = new Controller(null, $Response);
 
         $newResponse = new Response;
@@ -572,7 +575,9 @@ class ControllerTest extends TestCase
      */
     public function testReferer()
     {
-        $request = $this->getMock('Cake\Network\Request', ['referer']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['referer'])
+            ->getMock();
         $request->expects($this->any())->method('referer')
             ->with(true)
             ->will($this->returnValue('/posts/index'));
@@ -581,7 +586,9 @@ class ControllerTest extends TestCase
         $result = $Controller->referer(null, true);
         $this->assertEquals('/posts/index', $result);
 
-        $request = $this->getMock('Cake\Network\Request', ['referer']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['referer'])
+            ->getMock();
         $request->expects($this->any())->method('referer')
             ->with(true)
             ->will($this->returnValue('/posts/index'));
@@ -589,7 +596,9 @@ class ControllerTest extends TestCase
         $result = $Controller->referer(['controller' => 'posts', 'action' => 'index'], true);
         $this->assertEquals('/posts/index', $result);
 
-        $request = $this->getMock('Cake\Network\Request', ['referer']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['referer'])
+            ->getMock();
 
         $request->expects($this->any())->method('referer')
             ->with(false)
@@ -613,7 +622,9 @@ class ControllerTest extends TestCase
      */
     public function testRefererSlash()
     {
-        $request = $this->getMock('Cake\Network\Request', ['referer']);
+        $request = $this->getMockBuilder('Cake\Network\Request')
+            ->setMethods(['referer'])
+            ->getMock();
         $request->base = '/base';
         Router::pushRequest($request);
 
@@ -663,7 +674,7 @@ class ControllerTest extends TestCase
                     $this->attributeEqualTo('_subject', $controller)
                 )
             )
-            ->will($this->returnValue($this->getMock('Cake\Event\Event', null, [], '', false)));
+            ->will($this->returnValue($this->getMockBuilder('Cake\Event\Event')->disableOriginalConstructor()->getMock()));
 
         $eventManager->expects($this->at(1))->method('dispatch')
             ->with(
@@ -673,7 +684,7 @@ class ControllerTest extends TestCase
                     $this->attributeEqualTo('_subject', $controller)
                 )
             )
-            ->will($this->returnValue($this->getMock('Cake\Event\Event', null, [], '', false)));
+            ->will($this->returnValue($this->getMockBuilder('Cake\Event\Event')->disableOriginalConstructor()->getMock()));
 
         $controller->startupProcess();
     }
@@ -696,7 +707,7 @@ class ControllerTest extends TestCase
                     $this->attributeEqualTo('_subject', $controller)
                 )
             )
-            ->will($this->returnValue($this->getMock('Cake\Event\Event', null, [], '', false)));
+            ->will($this->returnValue($this->getMockBuilder('Cake\Event\Event')->disableOriginalConstructor()->getMock()));
 
         $controller->shutdownProcess();
     }
@@ -710,7 +721,9 @@ class ControllerTest extends TestCase
     {
         $request = new Request('controller_posts/index');
         $request->params['pass'] = [];
-        $response = $this->getMock('Cake\Network\Response', ['httpCodes']);
+        $response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['httpCodes'])
+            ->getMock();
 
         $Controller = new Controller($request, $response);
         $Controller->request->query['url'] = [];
@@ -740,7 +753,9 @@ class ControllerTest extends TestCase
     {
         $request = new Request('controller_posts/index');
         $request->params['pass'] = [];
-        $response = $this->getMock('Cake\Network\Response', ['httpCodes']);
+        $response = $this->getMockBuilder('Cake\Network\Response')
+            ->setMethods(['httpCodes'])
+            ->getMock();
 
         $Controller = new Controller($request, $response);
         $Controller->request->query['url'] = [];
@@ -906,7 +921,9 @@ class ControllerTest extends TestCase
     {
         $request = new Request('/');
         $response = $this->getMockBuilder('Cake\Network\Response')->getMock();
-        $componentRegistry = $this->getMock('Cake\Controller\ComponentRegistry', ['offsetGet']);
+        $componentRegistry = $this->getMockBuilder('Cake\Controller\ComponentRegistry')
+            ->setMethods(['offsetGet'])
+            ->getMock();
 
         $controller = new TestController($request, $response, null, null, $componentRegistry);
         $this->assertInstanceOf(get_class($componentRegistry), $controller->components());