|
24 | 24 | use Authentication\IdentityInterface;
|
25 | 25 | use Authentication\Middleware\AuthenticationMiddleware;
|
26 | 26 | use Authentication\Test\TestCase\AuthenticationTestCase as TestCase;
|
| 27 | +use Cake\Core\TestSuite\ContainerStubTrait; |
27 | 28 | use Cake\Http\Response;
|
28 | 29 | use Cake\Http\ServerRequestFactory;
|
29 | 30 | use Firebase\JWT\JWT;
|
|
32 | 33 |
|
33 | 34 | class AuthenticationMiddlewareTest extends TestCase
|
34 | 35 | {
|
| 36 | + use ContainerStubTrait; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var \Authentication\AuthenticationService |
| 40 | + */ |
| 41 | + protected $service; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var \TestApp\Application |
| 45 | + */ |
| 46 | + protected $application; |
| 47 | + |
35 | 48 | /**
|
36 | 49 | * Fixtures
|
37 | 50 | */
|
@@ -116,7 +129,7 @@ public function testApplicationAuthenticationRequestResponse()
|
116 | 129 | $service->method('getIdentityAttribute')->willReturn('identity');
|
117 | 130 |
|
118 | 131 | $application = $this->getMockBuilder(Application::class)
|
119 |
| - ->disableOriginalConstructor() |
| 132 | + ->setConstructorArgs(['config']) |
120 | 133 | ->onlyMethods(['getAuthenticationService', 'middleware'])
|
121 | 134 | ->getMock();
|
122 | 135 |
|
@@ -638,4 +651,20 @@ public function testCookieAuthorizationThroughTheMiddlewareStack()
|
638 | 651 |
|
639 | 652 | $this->assertStringContainsString('CookieAuth=%5B%22mariano%22', $response->getHeaderLine('Set-Cookie'));
|
640 | 653 | }
|
| 654 | + |
| 655 | + public function testMiddlewareInjectsServiceIntoDIC(): void |
| 656 | + { |
| 657 | + $request = ServerRequestFactory::fromGlobals( |
| 658 | + ['REQUEST_URI' => '/testpath'], |
| 659 | + [], |
| 660 | + ['username' => 'mariano', 'password' => 'password'] |
| 661 | + ); |
| 662 | + $handler = new TestRequestHandler(); |
| 663 | + |
| 664 | + $middleware = new AuthenticationMiddleware($this->application); |
| 665 | + $middleware->process($request, $handler); |
| 666 | + |
| 667 | + $container = $this->application->getContainer(); |
| 668 | + $this->assertInstanceOf(AuthenticationService::class, $container->get(AuthenticationService::class)); |
| 669 | + } |
641 | 670 | }
|
0 commit comments