Skip to content

Commit 4cc012b

Browse files
authored
Merge pull request #709 from cakephp/cleanup-tests
Cleanup tests.
2 parents 7486f10 + e1ef06a commit 4cc012b

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

tests/TestCase/Authenticator/SessionAuthenticatorTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Cake\Http\Exception\UnauthorizedException;
2525
use Cake\Http\Response;
2626
use Cake\Http\ServerRequestFactory;
27+
use Cake\Http\Session;
2728
use Cake\ORM\TableRegistry;
2829
use Psr\Http\Message\RequestInterface;
2930
use Psr\Http\Message\ResponseInterface;
@@ -58,11 +59,7 @@ public function setUp(): void
5859
'Authentication.Password',
5960
]);
6061

61-
$class = 'Cake\Http\Session';
62-
if (!class_exists($class)) {
63-
$class = '\Cake\Network\Session';
64-
}
65-
$this->sessionMock = $this->getMockBuilder($class)
62+
$this->sessionMock = $this->getMockBuilder(Session::class)
6663
->disableOriginalConstructor()
6764
->onlyMethods(['read', 'write', 'delete', 'renew', 'check'])
6865
->getMock();

tests/TestCase/Controller/Component/AuthenticationComponentTest.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class AuthenticationComponentTest extends TestCase
5555
*/
5656
protected $request;
5757

58-
/**
59-
* @var \Cake\Http\Response
60-
*/
61-
protected $response;
62-
6358
/**
6459
* @var \Authentication\AuthenticationService
6560
*/
@@ -574,7 +569,7 @@ public function testImpersonate()
574569
$request = $this->request
575570
->withAttribute('identity', $identity)
576571
->withAttribute('authentication', $this->service);
577-
$controller = new Controller($request, $this->response);
572+
$controller = new Controller($request);
578573
$registry = new ComponentRegistry($controller);
579574
$component = new AuthenticationComponent($registry);
580575

@@ -605,7 +600,7 @@ public function testImpersonateDecoratorIgnored()
605600
$request = $this->request
606601
->withAttribute('identity', $identity)
607602
->withAttribute('authentication', $this->service);
608-
$controller = new Controller($request, $this->response);
603+
$controller = new Controller($request);
609604
$registry = new ComponentRegistry($controller);
610605
$component = new AuthenticationComponent($registry);
611606

@@ -630,7 +625,7 @@ public function testImpersonateNoIdentity()
630625
$impersonated = new ArrayObject(['username' => 'larry']);
631626
$request = $this->request
632627
->withAttribute('authentication', $this->service);
633-
$controller = new Controller($request, $this->response);
628+
$controller = new Controller($request);
634629
$registry = new ComponentRegistry($controller);
635630
$component = new AuthenticationComponent($registry);
636631
$this->expectException(UnauthenticatedException::class);
@@ -659,7 +654,7 @@ public function testImpersonateFailure()
659654
$request = $this->request
660655
->withAttribute('identity', $identity)
661656
->withAttribute('authentication', $service);
662-
$controller = new Controller($request, $this->response);
657+
$controller = new Controller($request);
663658
$registry = new ComponentRegistry($controller);
664659
$component = new AuthenticationComponent($registry);
665660
$this->expectException(UnexpectedValueException::class);
@@ -680,7 +675,7 @@ public function testStopImpersonating()
680675
$this->request->getSession()->write('AuthImpersonate', $impersonator);
681676
$this->service->authenticate($this->request);
682677
$request = $this->request->withAttribute('authentication', $this->service);
683-
$controller = new Controller($request, $this->response);
678+
$controller = new Controller($request);
684679
$registry = new ComponentRegistry($controller);
685680
$component = new AuthenticationComponent($registry);
686681
$this->assertEquals($impersonator, $controller->getRequest()->getSession()->read('AuthImpersonate'));
@@ -710,7 +705,7 @@ public function testStopImpersonatingFailure()
710705
$request = $this->request
711706
->withAttribute('identity', $identity)
712707
->withAttribute('authentication', $service);
713-
$controller = new Controller($request, $this->response);
708+
$controller = new Controller($request);
714709
$registry = new ComponentRegistry($controller);
715710
$component = new AuthenticationComponent($registry);
716711
$this->expectException(UnexpectedValueException::class);
@@ -733,7 +728,7 @@ public function testIsImpersonating()
733728
$request = $this->request
734729
->withAttribute('authentication', $this->service)
735730
->withAttribute('identity', new Identity($impersonated));
736-
$controller = new Controller($request, $this->response);
731+
$controller = new Controller($request);
737732
$registry = new ComponentRegistry($controller);
738733
$component = new AuthenticationComponent($registry);
739734

@@ -757,7 +752,7 @@ public function testGetImpersonationAuthenticationServiceFailure()
757752
$request = $this->request
758753
->withAttribute('authentication', $service)
759754
->withAttribute('identity', new Identity($user));
760-
$controller = new Controller($request, $this->response);
755+
$controller = new Controller($request);
761756
$registry = new ComponentRegistry($controller);
762757
$component = new AuthenticationComponent($registry);
763758

@@ -778,7 +773,7 @@ public function testIsImpersonatingNotImpersonating()
778773
$this->request->getSession()->write('Auth', $user);
779774
$this->service->authenticate($this->request);
780775
$request = $this->request->withAttribute('authentication', $this->service);
781-
$controller = new Controller($request, $this->response);
776+
$controller = new Controller($request);
782777
$registry = new ComponentRegistry($controller);
783778
$component = new AuthenticationComponent($registry);
784779

0 commit comments

Comments
 (0)