Skip to content
Permalink
Browse files

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

  • Loading branch information...
ADmad committed Jun 4, 2016
1 parent 8dcf70d commit d00d7fdfe08c0a5ddb06bfd694780cb4cd8bb824
@@ -20,7 +20,6 @@
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 @@ public function setUp()
});
$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 @@ public function testIsErrorOrTests()
*/
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 @@ public function testIsAuthorizedMissingFile()
*/
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 @@ public function testIsAuthorizedDelegation()
*/
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 @@ public function testNoLoginRedirectForAuthenticatedUser()
$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 @@ public function testDefaultToLoginRedirect()
]);
$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 @@ public function testDefaultToLoginRedirect()
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 @@ public function testRedirectToUnauthorizedRedirect()
$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 @@ public function testRedirectToUnauthorizedRedirect()
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 @@ public function testRedirectToUnauthorizedRedirectLoginAction()
$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 @@ public function testRedirectToUnauthorizedRedirectLoginAction()
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 @@ public function testRedirectToUnauthorizedRedirectSuppressedAuthError()
$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 @@ public function testForbiddenException()
$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 @@ public function testForbiddenException()
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 @@ public function testAfterIdentifyForStatelessAuthentication()
*/
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 @@ public function testGettingUserAfterSetUser()
*/
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 @@ public function testStatelessAuthNoRedirect()
*/
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';
@@ -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;
Oops, something went wrong.

0 comments on commit d00d7fd

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