*/ class TestRunnerFeatureServiceTest extends GenerisPhpUnitTestRunner { //data to stub the registry content private static $pluginData = [ 'taoQtiTest/runner/plugins/myPlugin' => [ 'id' => 'myPlugin', 'module' => 'taoQtiTest/runner/plugins/myPlugin', 'category' => 'test', 'active' => true ], 'taoQtiTest/runner/plugins/controls/title/title' => [ 'id' => 'title', 'module' => 'taoQtiTest/runner/plugins/controls/title/title', 'category' => 'controls', 'active' => true ], 'taoQtiTest/runner/plugins/controls/timer/timer' => [ 'id' => 'timer', 'module' => 'taoQtiTest/runner/plugins/controls/timer/timer', 'category' => 'controls', 'active' => true ] ]; /** * Get the service with the stubbed registry * @return TestPluginService */ protected function getTestPluginService() { $testPluginService = new TestPluginService(); $pluginRegistryProphecy = $this->prophesize(PluginRegistry::class); $pluginRegistryProphecy->getMap()->willReturn(self::$pluginData); $testPluginService->setRegistry($pluginRegistryProphecy->reveal()); return $testPluginService; } public function testGetAll() { $feature1 = new TestFeature( 'myId1', ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ); $feature2 = new TestFeature( 'myId2', ['title', 'timer'], false, $this->getTestPluginService()->getAllPlugins() ); $feature3 = new TestFeature( 'myId3', ['title', 'timer'], false, $this->getTestPluginService()->getAllPlugins(), false ); $testRunnerFeatureService = new TestRunnerFeatureService(); $testRunnerFeatureService->register($feature1); $testRunnerFeatureService->register($feature2); $testRunnerFeatureService->register($feature3); $testRunnerFeatureService->setServiceLocator($this->getServiceLocatorMock([])); $registeredFeatures = $testRunnerFeatureService->getAll(); $this->assertEquals(2, count($registeredFeatures)); $this->assertEquals('myId1', $registeredFeatures['myId1']->getId()); $this->assertEquals('myId2', $registeredFeatures['myId2']->getId()); $registeredFeatures = $testRunnerFeatureService->getAll(false); $this->assertEquals(3, count($registeredFeatures)); } public function testCannotRegisterTwoFeaturesWithTheSameId() { $this->expectException(common_exception_InconsistentData::class); $feature1 = new TestFeature( 'myId1', ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ); $feature2 = new TestFeature( 'myId1', ['title', 'timer'], false, $this->getTestPluginService()->getAllPlugins() ); $testRunnerFeatureService = new TestRunnerFeatureService(); $testRunnerFeatureService->register($feature1); $testRunnerFeatureService->register($feature2); } public function testUnregisterFeature() { // first we register 2 features $feature1 = new TestFeature( 'myId1', ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ); $feature2 = new TestFeature( 'myId2', ['title', 'timer'], false, $this->getTestPluginService()->getAllPlugins() ); $testRunnerFeatureService = new TestRunnerFeatureService(); $testRunnerFeatureService->register($feature1); $testRunnerFeatureService->register($feature2); $testRunnerFeatureService->setServiceLocator($this->getServiceLocatorMock([])); $registeredFeatures = $testRunnerFeatureService->getAll(); $this->assertEquals(2, count($registeredFeatures)); $this->assertEquals('myId1', $registeredFeatures['myId1']->getId()); $this->assertEquals('myId2', $registeredFeatures['myId2']->getId()); // then we remove the first one $testRunnerFeatureService->unregister('myId1'); $registeredFeatures = $testRunnerFeatureService->getAll(); $this->assertEquals(1, count($registeredFeatures)); // then the second one $testRunnerFeatureService->unregister('myId2'); $registeredFeatures = $testRunnerFeatureService->getAll(); $this->assertEquals(0, count($registeredFeatures)); } public function testUnregisterBadId() { $testLogger = new TestLogger(); $testRunnerFeatureService = new TestRunnerFeatureService(); $testRunnerFeatureService->setLogger($testLogger); $testRunnerFeatureService->unregister('idontexist'); $this->assertTrue($testLogger->has(LogLevel::WARNING, 'Cannot unregister inexistant feature idontexist')); } }