*/ class TestRunnerFeatureTest extends TestCase { //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 ], 'taoQtiTest/runner/plugins/inactive' => [ 'id' => 'inactive', 'module' => 'taoQtiTest/runner/plugins/inactive', 'category' => 'test', 'active' => false ] ]; /** * Get the service with the stubbed registry * @return TestPluginService */ protected function getTestPluginService() { $prophecy = $this->prophesize(PluginRegistry::class); $prophecy->getMap()->willReturn(self::$pluginData); $testPluginService = new TestPluginService(); $testPluginService->setRegistry($prophecy->reveal()); return $testPluginService; } /** * */ public function provideBadConstructorParameters() { return [ // bad id [ '', ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ], [ 69, ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ], // bad pluginId [ 'myId', '', true, $this->getTestPluginService()->getAllPlugins() ], [ 'myId', [], true, $this->getTestPluginService()->getAllPlugins() ], [ 'myId', [69], true, $this->getTestPluginService()->getAllPlugins() ], // bad isEnabledByDefault [ 'myId', ['myPlugin'], null, $this->getTestPluginService()->getAllPlugins() ], [ 'myId', ['myPlugin'], 'true', $this->getTestPluginService()->getAllPlugins() ], // bad allPlugins [ 'myId', ['myPlugin'], true, ''], [ 'myId', ['myPlugin'], true, []], [ 'myId', ['myPlugin'], true, ['myPlugin']], ]; } /** * @param string $id * @param string[] $pluginsIds * @param bool $isEnabledByDefault * @param TestPlugin[] $allPlugins * * @dataProvider provideBadConstructorParameters */ public function testBadConstructorParameters($id, $pluginsIds, $isEnabledByDefault, $allPlugins) { $this->expectException(common_exception_InconsistentData::class); new TestFeature( $id, $pluginsIds, $isEnabledByDefault, $allPlugins ); } public function testConstructPluginsIdNotInRegistry() { $feature = new TestFeature( 'myId', ['iDontExist'], true, $this->getTestPluginService()->getAllPlugins() ); $testLogger = new TestLogger(); $serviceLocatorMock = $this->getServiceLocatorMock([ LoggerService::SERVICE_ID => $testLogger ]); $feature->setServiceLocator($serviceLocatorMock); $feature->getPluginsIds(); $this->assertTrue($testLogger->has(LogLevel::WARNING, 'Invalid plugin Id iDontExist for test runner feature myId')); } public function testConstructEmptyLabel() { $this->expectException(common_exception_InconsistentData::class); new TestFeatureEmptyLabel( 'myId', ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ); } public function testConstructEmptyDescription() { $this->expectException(common_exception_InconsistentData::class); new TestFeatureEmptyDescription( 'myId', ['myPlugin'], true, $this->getTestPluginService()->getAllPlugins() ); } private static $featureData = [ 'id' => 'myId', 'pluginsIds' => ['myPlugin', 'timer', 'title'], 'isEnabledByDefault' => false ]; public function getTestFeature() { return new TestFeature( self::$featureData['id'], self::$featureData['pluginsIds'], self::$featureData['isEnabledByDefault'], $this->getTestPluginService()->getAllPlugins() ); } public function testConstruct() { $feature = $this->getTestFeature(); $this->assertEquals(self::$featureData['id'], $feature->getId()); $this->assertEquals(self::$featureData['pluginsIds'], $feature->getPluginsIds()); $this->assertEquals(self::$featureData['isEnabledByDefault'], $feature->isEnabledByDefault()); $this->assertEquals('testFeature', $feature->getLabel()); $this->assertEquals('A simple feature used for unit testing', $feature->getDescription()); } public function testPhpSerialize() { $feature = $this->getTestFeature(); $this->assertEquals( 'new oat\taoTests\test\integration\runner\features\samples\TestFeature()', $feature->__toPhpCode() ); } }