|
17 | 17 | namespace Authentication\Test\TestCase\Middleware; |
18 | 18 |
|
19 | 19 | use Authentication\AuthenticationService; |
20 | | -use Authentication\AuthenticationServiceInterface; |
21 | 20 | use Authentication\AuthenticationServiceProviderInterface; |
22 | | -use Authentication\Authenticator\ResultInterface; |
23 | 21 | use Authentication\Authenticator\UnauthenticatedException; |
24 | 22 | use Authentication\IdentityInterface; |
25 | 23 | use Authentication\Middleware\AuthenticationMiddleware; |
26 | 24 | use Authentication\Test\TestCase\AuthenticationTestCase as TestCase; |
| 25 | +use Cake\Core\TestSuite\ContainerStubTrait; |
27 | 26 | use Cake\Http\Response; |
28 | 27 | use Cake\Http\ServerRequestFactory; |
29 | 28 | use Cake\Http\Uri; |
|
33 | 32 |
|
34 | 33 | class AuthenticationMiddlewareTest extends TestCase |
35 | 34 | { |
| 35 | + use ContainerStubTrait; |
| 36 | + |
36 | 37 | /** |
37 | 38 | * Fixtures |
38 | 39 | */ |
@@ -105,31 +106,6 @@ public function testProviderAuthentication() |
105 | 106 | $this->assertTrue($service->authenticators()->has('Form')); |
106 | 107 | } |
107 | 108 |
|
108 | | - public function testApplicationAuthenticationRequestResponse() |
109 | | - { |
110 | | - $request = ServerRequestFactory::fromGlobals(); |
111 | | - $handler = new TestRequestHandler(); |
112 | | - |
113 | | - $service = $this->createMock(AuthenticationServiceInterface::class); |
114 | | - |
115 | | - $service->method('authenticate') |
116 | | - ->willReturn($this->createMock(ResultInterface::class)); |
117 | | - $service->method('getIdentityAttribute')->willReturn('identity'); |
118 | | - |
119 | | - $application = $this->getMockBuilder(Application::class) |
120 | | - ->disableOriginalConstructor() |
121 | | - ->setMethods(['getAuthenticationService', 'middleware']) |
122 | | - ->getMock(); |
123 | | - |
124 | | - $application->expects($this->once()) |
125 | | - ->method('getAuthenticationService') |
126 | | - ->with($request) |
127 | | - ->willReturn($service); |
128 | | - |
129 | | - $middleware = new AuthenticationMiddleware($application); |
130 | | - $middleware->process($request, $handler); |
131 | | - } |
132 | | - |
133 | 109 | public function testInvalidSubject() |
134 | 110 | { |
135 | 111 | $this->expectException('InvalidArgumentException'); |
@@ -770,4 +746,20 @@ public function testServiceConfigurationFallback() |
770 | 746 | $this->assertSame('redirect', $service->getConfig('queryParam')); |
771 | 747 | $this->assertSame('/login', $service->getConfig('unauthenticatedRedirect')); |
772 | 748 | } |
| 749 | + |
| 750 | + public function testMiddlewareInjectsServiceIntoDIC(): void |
| 751 | + { |
| 752 | + $request = ServerRequestFactory::fromGlobals( |
| 753 | + ['REQUEST_URI' => '/testpath'], |
| 754 | + [], |
| 755 | + ['username' => 'mariano', 'password' => 'password'] |
| 756 | + ); |
| 757 | + $handler = new TestRequestHandler(); |
| 758 | + |
| 759 | + $middleware = new AuthenticationMiddleware($this->application); |
| 760 | + $middleware->process($request, $handler); |
| 761 | + |
| 762 | + $container = $this->application->getContainer(); |
| 763 | + $this->assertInstanceOf(AuthenticationService::class, $container->get(AuthenticationService::class)); |
| 764 | + } |
773 | 765 | } |
0 commit comments