|
24 | 24 | use Authentication\IdentityInterface; |
25 | 25 | use Authentication\Middleware\AuthenticationMiddleware; |
26 | 26 | use Authentication\Test\TestCase\AuthenticationTestCase as TestCase; |
| 27 | +use Cake\Core\Container; |
27 | 28 | use Cake\Core\TestSuite\ContainerStubTrait; |
28 | 29 | use Cake\Http\Response; |
29 | 30 | use Cake\Http\ServerRequestFactory; |
@@ -667,4 +668,25 @@ public function testMiddlewareInjectsServiceIntoDIC(): void |
667 | 668 | $container = $this->application->getContainer(); |
668 | 669 | $this->assertInstanceOf(AuthenticationService::class, $container->get(AuthenticationService::class)); |
669 | 670 | } |
| 671 | + |
| 672 | + public function testMiddlewareInjectsServiceIntoDICCustomContainerInstance(): void |
| 673 | + { |
| 674 | + $request = ServerRequestFactory::fromGlobals( |
| 675 | + ['REQUEST_URI' => '/testpath'], |
| 676 | + [], |
| 677 | + ['username' => 'mariano', 'password' => 'password'] |
| 678 | + ); |
| 679 | + $handler = new TestRequestHandler(); |
| 680 | + |
| 681 | + $provider = $this->createMock(AuthenticationServiceProviderInterface::class); |
| 682 | + $provider |
| 683 | + ->method('getAuthenticationService') |
| 684 | + ->willReturn($this->service); |
| 685 | + $container = new Container(); |
| 686 | + |
| 687 | + $middleware = new AuthenticationMiddleware($provider, $container); |
| 688 | + $middleware->process($request, $handler); |
| 689 | + |
| 690 | + $this->assertInstanceOf(AuthenticationService::class, $container->get(AuthenticationService::class)); |
| 691 | + } |
670 | 692 | } |
0 commit comments