Browse Source

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

ADmad 9 years ago
parent
commit
c5963ca6de

+ 4 - 2
tests/TestCase/Auth/BasicAuthenticateTest.php

@@ -15,9 +15,11 @@
 namespace Cake\Test\TestCase\Auth;
 
 use Cake\Auth\BasicAuthenticate;
+use Cake\Controller\ComponentRegistry;
 use Cake\I18n\Time;
 use Cake\Network\Exception\UnauthorizedException;
 use Cake\Network\Request;
+use Cake\Network\Response;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
 
@@ -44,7 +46,7 @@ class BasicAuthenticateTest extends TestCase
     {
         parent::setUp();
 
-        $this->Collection = $this->getMock('Cake\Controller\ComponentRegistry');
+        $this->Collection = $this->getMockBuilder(ComponentRegistry::class)->getMock();
         $this->auth = new BasicAuthenticate($this->Collection, [
             'userModel' => 'Users',
             'realm' => 'localhost'
@@ -53,7 +55,7 @@ class BasicAuthenticateTest extends TestCase
         $password = password_hash('password', PASSWORD_BCRYPT);
         $User = TableRegistry::get('Users');
         $User->updateAll(['password' => $password], []);
-        $this->response = $this->getMock('Cake\Network\Response');
+        $this->response = $this->getMockBuilder(Response::class)->getMock();
     }
 
     /**

+ 6 - 2
tests/TestCase/Auth/ControllerAuthorizeTest.php

@@ -17,6 +17,7 @@
 namespace Cake\Test\TestCase\Auth;
 
 use Cake\Auth\ControllerAuthorize;
+use Cake\Controller\ComponentRegistry;
 use Cake\Controller\Controller;
 use Cake\Network\Request;
 use Cake\TestSuite\TestCase;
@@ -36,8 +37,11 @@ class ControllerAuthorizeTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->controller = $this->getMock('Cake\Controller\Controller', ['isAuthorized'], [], '', false);
-        $this->components = $this->getMock('Cake\Controller\ComponentRegistry');
+        $this->controller = $this->getMockBuilder(Controller::class)
+            ->setMethods(['isAuthorized'])
+            ->disableOriginalConstructor()
+            ->getMock();
+        $this->components = $this->getMockBuilder(ComponentRegistry::class)->getMock();
         $this->components->expects($this->any())
             ->method('getController')
             ->will($this->returnValue($this->controller));

+ 4 - 2
tests/TestCase/Auth/DigestAuthenticateTest.php

@@ -17,9 +17,11 @@
 namespace Cake\Test\TestCase\Auth;
 
 use Cake\Auth\DigestAuthenticate;
+use Cake\Controller\ComponentRegistry;
 use Cake\I18n\Time;
 use Cake\Network\Exception\UnauthorizedException;
 use Cake\Network\Request;
+use Cake\Network\Response;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
 
@@ -46,7 +48,7 @@ class DigestAuthenticateTest extends TestCase
     {
         parent::setUp();
 
-        $this->Collection = $this->getMock('Cake\Controller\ComponentRegistry');
+        $this->Collection = $this->getMockBuilder(ComponentRegistry::class)->getMock();
         $this->auth = new DigestAuthenticate($this->Collection, [
             'realm' => 'localhost',
             'nonce' => 123,
@@ -57,7 +59,7 @@ class DigestAuthenticateTest extends TestCase
         $User = TableRegistry::get('Users');
         $User->updateAll(['password' => $password], []);
 
-        $this->response = $this->getMock('Cake\Network\Response');
+        $this->response = $this->getMockBuilder(Response::class)->getMock();
     }
 
     /**

+ 10 - 12
tests/TestCase/Auth/FormAuthenticateTest.php

@@ -15,10 +15,11 @@
 namespace Cake\Test\TestCase\Auth;
 
 use Cake\Auth\FormAuthenticate;
-use Cake\Core\Configure;
+use Cake\Controller\ComponentRegistry;
 use Cake\Core\Plugin;
 use Cake\I18n\Time;
 use Cake\Network\Request;
+use Cake\Network\Response;
 use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
@@ -46,7 +47,7 @@ class FormAuthenticateTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->Collection = $this->getMock('Cake\Controller\ComponentRegistry');
+        $this->Collection = $this->getMockBuilder(ComponentRegistry::class)->getMock();
         $this->auth = new FormAuthenticate($this->Collection, [
             'userModel' => 'Users'
         ]);
@@ -61,7 +62,7 @@ class FormAuthenticateTest extends TestCase
         ]);
         $AuthUsers->updateAll(['password' => $password], []);
 
-        $this->response = $this->getMock('Cake\Network\Response');
+        $this->response = $this->getMockBuilder(Response::class)->getMock();
     }
 
     /**
@@ -144,16 +145,13 @@ class FormAuthenticateTest extends TestCase
             'password' => ''
         ];
 
-        $this->auth = $this->getMock(
-            'Cake\Auth\FormAuthenticate',
-            ['_checkFields'],
-            [
+        $this->auth = $this->getMockBuilder(FormAuthenticate::class)
+            ->setMethods(['_checkFields'])
+            ->setConstructorArgs([
                 $this->Collection,
-                [
-                    'userModel' => 'Users'
-                ]
-            ]
-        );
+                ['userModel' => 'Users']
+            ])
+            ->getMock();
 
         // Simulate that check for ensuring password is not empty is missing.
         $this->auth->expects($this->once())

+ 2 - 1
tests/TestCase/Auth/Storage/SessionStorageTest.php

@@ -17,6 +17,7 @@ namespace Cake\Test\TestCase\Auth;
 use Cake\Auth\Storage\SessionStorage;
 use Cake\Network\Request;
 use Cake\Network\Response;
+use Cake\Network\Session;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -35,7 +36,7 @@ class SessionStorageTest extends TestCase
     {
         parent::setUp();
 
-        $this->session = $this->getMock('Cake\Network\Session');
+        $this->session = $this->getMockBuilder(Session::class)->getMock();
         $this->request = new Request(['session' => $this->session]);
         $this->response = new Response();
         $this->storage = new SessionStorage($this->request, $this->response, ['key' => 'Auth.AuthUser']);