diff options
Diffstat (limited to 'tests/lib/AppFramework/DependencyInjection/DIContainerTest.php')
-rw-r--r-- | tests/lib/AppFramework/DependencyInjection/DIContainerTest.php | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php index bcf4e0a2771..04422643121 100644 --- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php +++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php @@ -26,8 +26,8 @@ namespace Test\AppFramework\DependencyInjection; use OC\AppFramework\Bootstrap\Coordinator; +use OC\AppFramework\Bootstrap\MiddlewareRegistration; use OC\AppFramework\Bootstrap\RegistrationContext; -use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\Security\SecurityMiddleware; @@ -95,8 +95,40 @@ class DIContainerTest extends \Test\TestCase { $registrationContext = $this->createMock(RegistrationContext::class); $registrationContext->method('getMiddlewareRegistrations') ->willReturn([ - new ServiceRegistration($this->container['appName'], 'foo'), - new ServiceRegistration('otherapp', 'bar'), + new MiddlewareRegistration($this->container['appName'], 'foo', false), + new MiddlewareRegistration('otherapp', 'bar', false), + ]); + $this->container['foo'] = new class extends Middleware { + }; + $this->container['bar'] = new class extends Middleware { + }; + $coordinator->method('getRegistrationContext')->willReturn($registrationContext); + + $dispatcher = $this->container['MiddlewareDispatcher']; + + $middlewares = $dispatcher->getMiddlewares(); + self::assertNotEmpty($middlewares); + foreach ($middlewares as $middleware) { + if ($middleware === $this->container['bar']) { + $this->fail('Container must not register this middleware'); + } + if ($middleware === $this->container['foo']) { + // It is done + return; + } + } + $this->fail('Bootstrap registered middleware not found'); + } + + public function testMiddlewareDispatcherIncludesGlobalBootstrapMiddlewares(): void { + $coordinator = $this->createMock(Coordinator::class); + $this->container[Coordinator::class] = $coordinator; + $this->container['Request'] = $this->createMock(Request::class); + $registrationContext = $this->createMock(RegistrationContext::class); + $registrationContext->method('getMiddlewareRegistrations') + ->willReturn([ + new MiddlewareRegistration('otherapp', 'foo', true), + new MiddlewareRegistration('otherapp', 'bar', false), ]); $this->container['foo'] = new class extends Middleware { }; |