Skip to content
Permalink
Browse files

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

  • Loading branch information...
ADmad committed Jun 4, 2016
1 parent cbe6efa commit c5963ca6deba894b322980769e21713375f45628
@@ -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 @@ public function setUp()
{
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 @@ public function setUp()
$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();
}
/**
@@ -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));
@@ -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 @@ public function setUp()
{
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 @@ public function setUp()
$User = TableRegistry::get('Users');
$User->updateAll(['password' => $password], []);
$this->response = $this->getMock('Cake\Network\Response');
$this->response = $this->getMockBuilder(Response::class)->getMock();
}
/**
@@ -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 @@ public function setUp()
]);
$AuthUsers->updateAll(['password' => $password], []);
$this->response = $this->getMock('Cake\Network\Response');
$this->response = $this->getMockBuilder(Response::class)->getMock();
}
/**
@@ -144,16 +145,13 @@ public function testAuthenticatePasswordIsEmptyString()
'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())
@@ -17,6 +17,7 @@
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 @@ public function setUp()
{
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']);

0 comments on commit c5963ca

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