logger = $this->createMock(LoggerInterface::class); $this->context = Server::get(RegistrationContext::class); $this->dispatcher = Server::get(IEventDispatcher::class); $this->discoveryService = Server::get(OCMDiscoveryService::class); $this->config = Server::get(IConfig::class); // reset $localProvider value between tests $reflection = new ReflectionClass($this->discoveryService); $localProvider = $reflection->getProperty('localProvider'); $localProvider->setValue($this->discoveryService, null); $this->requestController = Server::get(OCMRequestController::class); } public static function dataTestOCMRequest(): array { return [ ['/inexistant-path/', 404, null], ['/ocm-capability-test/', 404, null], ['/ocm-capability-test/get', 200, [ 'capability' => 'ocm-capability-test', 'path' => '/get', 'args' => ['get'], 'totalArgs' => 1, 'typedArgs' => ['get'], ] ], ['/ocm-capability-test/get/10/', 200, [ 'capability' => 'ocm-capability-test', 'path' => '/get/10', 'args' => ['get', '10'], 'totalArgs' => 2, 'typedArgs' => ['get', '10'], ] ], ['/ocm-capability-test/get/random/10/', 200, [ 'capability' => 'ocm-capability-test', 'path' => '/get/random/10', 'args' => ['get', 'random', '10'], 'totalArgs' => 3, 'typedArgs' => ['get', 'random', 10], ] ], ['/ocm-capability-test/get/random/10/1', 200, [ 'capability' => 'ocm-capability-test', 'path' => '/get/random/10/1', 'args' => ['get', 'random', '10', '1'], 'totalArgs' => 4, 'typedArgs' => ['get', 'random', 10, true], ] ], ['/ocm-capability-test/get/random/10/true', 200, [ 'capability' => 'ocm-capability-test', 'path' => '/get/random/10/true', 'args' => ['get', 'random', '10', 'true'], 'totalArgs' => 4, 'typedArgs' => ['get', 'random', 10, true], ] ], ['/ocm-capability-test/get/random/10/true/42', 200, [ 'capability' => 'ocm-capability-test', 'path' => '/get/random/10/true/42', 'args' => ['get', 'random', '10', 'true', '42'], 'totalArgs' => 5, 'typedArgs' => ['get', 'random', 10, true, 42], ] ], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataTestOCMRequest')] public function testOCMRequest(string $path, int $expectedStatus, ?array $expectedResult): void { $this->context->for('ocm-request-app')->registerEventListener(OCMEndpointRequestEvent::class, OCMEndpointRequestTestEvent::class); $this->context->delegateEventListenerRegistrations($this->dispatcher); $response = $this->requestController->manageOCMRequests($path); $this->assertSame($expectedStatus, $response->getStatus()); if ($expectedResult !== null) { $this->assertSame($expectedResult, $response->getData()); } } public function testLocalBaseCapability(): void { $local = $this->discoveryService->getLocalOCMProvider(); $this->assertEmpty(array_diff(['notifications', 'shares'], $local->getCapabilities())); } public function testLocalAddedCapability(): void { $this->context->for('ocm-capability-app')->registerEventListener(LocalOCMDiscoveryEvent::class, LocalOCMDiscoveryTestEvent::class); $this->context->delegateEventListenerRegistrations($this->dispatcher); $local = $this->discoveryService->getLocalOCMProvider(); $this->assertEmpty(array_diff(['notifications', 'shares', 'ocm-capability-test'], $local->getCapabilities())); } }