overriddenOptionsRepositoryMock = $this->createMock(OverriddenOptionsRepositoryInterface::class); $this->service = new QtiRunnerMap(); $this->service->setServiceLocator( $this->getServiceLocatorMock([ OverriddenOptionsRepositoryInterface::SERVICE_ID => $this->overriddenOptionsRepositoryMock, ]) ); } /** * @dataProvider categoryProvider * @param array $itemCategories * @param array $overriddenCategories * @param array $expectedCategoryList */ public function testGetAvailableCategories_WhenOverridesAreRegistered_ThenCategoriesAreFiltered( array $itemCategories, array $overriddenCategories, array $expectedCategoryList ): void { $this->setOverriddenOptionsRepositoryResult($overriddenCategories); $item = new AssessmentItemRef('itemId1', 'itemHref', new IdentifierCollection($itemCategories)); $this->assertSame($expectedCategoryList, $this->invokeGetAvailableCategories($item)); } public function categoryProvider(): array { return [ [[], [], []], [[], ['toolName' => true], ['x-tao-option-toolName']], [['x-tao-option-toolName'], ['toolName' => true], ['x-tao-option-toolName']], [['x-tao-option-tool-name'], ['toolName' => true], ['x-tao-option-tool-name', 'x-tao-option-toolName']], [['x-tao-option-tool-name', 'x-tao-option-toolName', 'tool_name'], ['toolName' => false], []], [['x-tao-option-tool-name'], ['fakeCategory' => false], ['x-tao-option-tool-name']], ]; } private function setOverriddenOptionsRepositoryResult(array $overriddenCategories): void { $list = []; foreach ($overriddenCategories as $categoryId => $isEnabled) { $list[] = new Option($categoryId, $isEnabled); } $this->overriddenOptionsRepositoryMock->method('findAll')->willReturn(new OptionCollection(...$list)); } private function invokeGetAvailableCategories(AssessmentItemRef $item): array { $reflection = new ReflectionClass(get_class($this->service)); $method = $reflection->getMethod('getAvailableCategories'); $method->setAccessible(true); return $method->invokeArgs($this->service, [$item]); } }