protected function configureApplicationContext() { $environment = new Environment(); $environment->setWorkingDirectoryAtStartup(function_exists('Stagehand\\TestRunner\\Core\\workingDirectoryAtStartup') ? workingDirectoryAtStartup() : $GLOBALS['STAGEHAND_TESTRUNNER_workingDirectoryAtStartup']); $environment->setPreloadScript(function_exists('Stagehand\\TestRunner\\Core\\preloadScript') ? preloadScript() : $GLOBALS['STAGEHAND_TESTRUNNER_preloadScript']); $applicationContext = new ApplicationContext(); $applicationContext->setComponentFactory(new ComponentFactory()); $applicationContext->setEnvironment($environment); ApplicationContext::setInstance($applicationContext); }
protected function configureApplicationContext() { $environment = new Environment(); $environment->setWorkingDirectoryAtStartup(workingDirectoryAtStartup()); $environment->setPreloadScript(preloadScript()); $applicationContext = new ApplicationContext(); $applicationContext->setComponentFactory(new ComponentFactory()); $applicationContext->setEnvironment($environment); ApplicationContext::setInstance($applicationContext); }
public static function earlyInitialize() { $classLoader = new UniversalClassLoader(); $classLoader->registerNamespace('Stagehand\\TestRunner', array(__DIR__ . '/../../..', __DIR__ . '/../../../../examples')); $classLoader->registerPrefix('Stagehand_TestRunner_', __DIR__ . '/../../../../examples'); $classLoader->register(); self::$applicationContext = new TestApplicationContext(); self::$applicationContext->setComponentFactory(new TestComponentFactory()); self::$applicationContext->setEnvironment(new self()); self::$applicationContext->setPlugin(PluginRepository::findByPluginID(PHPUnitPlugin::getPluginID())); ApplicationContext::setInstance(self::$applicationContext); $container = new Container(); $transformation = new Transformation($container); $transformation->transformToContainerParameters(); ApplicationContext::getInstance()->getComponentFactory()->setContainer($container); }
protected function tearDown() { $this->applicationContext->getComponentFactory()->clearComponents(); ApplicationContext::getInstance()->getEnvironment()->setWorkingDirectoryAtStartup(null); ApplicationContext::getInstance()->getEnvironment()->setPreloadScript(null); ApplicationContext::setInstance($this->oldApplicationContext); }
public function prepare() { if (defined('STAGEHAND_TESTRUNNER_PREPARER_CAKEPREPARER_PREPARECALLEDMARKER')) { return; } define('STAGEHAND_TESTRUNNER_PREPARER_CAKEPREPARER_PREPARECALLEDMARKER', true); if (!defined('DISABLE_AUTO_DISPATCH')) { define('DISABLE_AUTO_DISPATCH', true); } if (is_null($this->getCakePHPAppPath())) { $cakephpAppPath = ApplicationContext::getInstance()->getEnvironment()->getWorkingDirectoryAtStartup(); } else { $cakephpAppPath = $this->getCakePHPAppPath(); } $rootPath = realpath($cakephpAppPath . '/..'); $appPath = basename(realpath($cakephpAppPath)); if (is_null($this->getCakePHPCorePath())) { $corePath = $rootPath . DIRECTORY_SEPARATOR . 'cake'; } else { $corePath = realpath($this->getCakePHPCorePath()); } if (!defined('TEST_CAKE_CORE_INCLUDE_PATH')) { define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); } ob_start(); require_once $corePath . '/console/cake.php'; ob_end_clean(); new TestRunnerShellDispatcher(array('-root', $rootPath, '-app', $appPath)); require_once $corePath . '/tests/lib/test_manager.php'; new \TestManager(); }
/** * @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder */ protected function defineGrammar(NodeBuilder $nodeBuilder) { $nodeBuilder->scalarNode('framework')->end()->arrayNode('test_targets')->addDefaultsIfNotSet()->children()->arrayNode('resources')->defaultValue(array(ApplicationContext::getInstance()->getEnvironment()->getWorkingDirectoryAtStartup()))->validate()->ifTrue(function ($v) { return count($v) == 0; })->then(function ($v) { return array(ApplicationContext::getInstance()->getEnvironment()->getWorkingDirectoryAtStartup()); })->end()->prototype('scalar')->cannotBeEmpty()->end()->end()->booleanNode('recursive')->defaultFalse()->end()->arrayNode('methods')->defaultValue(array())->prototype('scalar')->cannotBeEmpty()->end()->end()->arrayNode('classes')->defaultValue(array())->prototype('scalar')->cannotBeEmpty()->end()->end()->scalarNode('file_pattern')->defaultNull()->cannotBeEmpty()->end()->end()->end()->arrayNode('autotest')->addDefaultsIfNotSet()->treatNullLike(array('enabled' => true))->treatTrueLike(array('enabled' => true))->treatFalseLike(array('enabled' => false))->children()->booleanNode('enabled')->defaultFalse()->end()->arrayNode('watch_dirs')->defaultValue(array())->prototype('scalar')->cannotBeEmpty()->end()->end()->end()->end()->booleanNode('notify')->defaultFalse()->end()->arrayNode('junit_xml')->addDefaultsIfNotSet()->beforeNormalization()->ifString()->then(function ($v) { return array('file' => $v); })->end()->children()->scalarNode('file')->defaultNull()->cannotBeEmpty()->end()->booleanNode('realtime')->defaultFalse()->end()->end()->end()->booleanNode('stop_on_failure')->defaultFalse()->end()->booleanNode('detailed_progress')->defaultFalse()->end(); }
public function prepare() { parent::prepare(); if (is_null($this->getCIUnitPath())) { $ciunitPath = ApplicationContext::getInstance()->getEnvironment()->getWorkingDirectoryAtStartup(); } else { $ciunitPath = $this->getCIUnitPath(); } /* Removes some superglobals and environment variables to avoid getting invalid * URI string by the CIUnit URI object since some cases PDT sets some * environment variables for debugging. */ $this->backupVariables(); ErrorReporting::invokeWith(error_reporting() & ~E_USER_NOTICE, function () use($ciunitPath) { require_once $ciunitPath . '/CIUnit.php'; }); $this->restoreVariables(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!class_exists(Compiler::COMPILED_CONTAINER_NAMESPACE . '\\PHPUnitContainer')) { $output->writeln('<error>Please run the following command before running the ' . $this->getName() . ' command:</error>' . PHP_EOL . PHP_EOL . ' <info>testrunner compile</info>'); return 1; } $container = $this->createContainer(); ApplicationContext::getInstance()->getComponentFactory()->setContainer($container); ApplicationContext::getInstance()->setComponent('environment', ApplicationContext::getInstance()->getEnvironment()); ApplicationContext::getInstance()->setComponent('input', $input); ApplicationContext::getInstance()->setComponent('output', $output); ApplicationContext::getInstance()->setComponent('plugin', PluginRepository::findByPluginID(PHPUnitPlugin::getPluginID())); ApplicationContext::getInstance()->createComponent('preparer')->prepare(); $collector = ApplicationContext::getInstance()->createComponent('collector'); $collector->setRecursive(true); define('PHPUnit_MAIN_METHOD', __METHOD__); $command = new \Stagehand\TestRunner\CLI\TestRunnerApplication\Command\PHPUnitPassthroughCommand\Command($collector, ApplicationContext::getInstance()->createComponent('test_target_repository')); if ($input->getOption('phpunit-help')) { return $command->run(array_merge($this->removeTestRunnerArguments($_SERVER['argv'], array('--phpunit-help')), array('--help')), false); } return $command->run($this->removeTestRunnerArguments($_SERVER['argv']), false); }
protected function getCommandName(InputInterface $input) { $commandName = parent::getCommandName($input); if (is_null($commandName)) { return null; } else { if ($commandName == ApplicationContext::getInstance()->getEnvironment()->getPreloadScript()) { return null; } else { return $commandName; } } }
/** * @return \Stagehand\TestRunner\CLI\TestRunner */ protected function createTestRunner() { return ApplicationContext::getInstance()->createComponent('test_runner'); }
/** * @param bool $continuousTesting * * @return \Stagehand\TestRunner\Process\TestRunnerInterface */ protected function createTestRunner($continuousTesting) { if ($continuousTesting) { return ApplicationContext::getInstance()->createComponent('continuous_test_runner'); } else { return ApplicationContext::getInstance()->createComponent('test_runner'); } }
public function transformToContainerParameters() { if (!is_null($this->configurationFile)) { foreach (Yaml::parse($this->configurationFile) as $configurationID => $configurationPart) { if (!is_null($configurationPart)) { if (!array_key_exists($configurationID, $this->configuration)) { $this->configuration[$configurationID] = array(); } array_unshift($this->configuration[$configurationID], $configurationPart); } } } foreach ($this->configuration as $configurationID => $configurationParts) { $configurations = array(); foreach ($configurationParts as $configurationPart) { $configurations[] = $configurationPart; } if ($configurationID == GeneralConfiguration::getConfigurationID()) { $transformerID = 'General'; } else { $plugin = PluginRepository::findByPluginID($configurationID); $transformerID = $plugin->getPluginID(); } $transformerClass = __NAMESPACE__ . '\\' . $transformerID . 'Transformer'; $transformer = new $transformerClass($configurations, $this->container); /* @var $transformer \Stagehand\TestRunner\DependencyInjection\Transformation\Transformer */ $transformer->transform(); } if (is_null($this->container->getParameter('test_file_pattern'))) { $this->container->setParameter('test_file_pattern', ApplicationContext::getInstance()->getPlugin()->getTestFilePattern()); } }
/** * @param string $componentID * @return string */ protected function resolveComponentID($componentID) { return ApplicationContext::getInstance()->getPlugin()->getPluginID() . '.' . $componentID; }
/** * @return array */ protected function buildRunnerOptions() { $options = array(); if (basename(trim($this->runnerCommand, '\'"')) != 'testrunner') { $configFile = $this->getPHPConfigDir(); if ($configFile !== false) { $options[] = '-c'; $options[] = escapeshellarg($configFile); } $options[] = escapeshellarg($_SERVER['argv'][0]); } if ($this->terminal->shouldColor()) { $options[] = '--ansi'; } $options[] = escapeshellarg(strtolower(ApplicationContext::getInstance()->getPlugin()->getPluginID())); if (!is_null(ApplicationContext::getInstance()->getEnvironment()->getPreloadScript())) { $options[] = '-p ' . escapeshellarg(ApplicationContext::getInstance()->getEnvironment()->getPreloadScript()); } $options[] = '-R'; if ($this->runnerFactory->create()->shouldNotify()) { $options[] = '-m'; } if ($this->runnerFactory->create()->shouldStopOnFailure()) { $options[] = '--stop-on-failure'; } if (!$this->testTargetRepository->isDefaultFilePattern()) { $options[] = '--test-file-pattern=' . escapeshellarg($this->testTargetRepository->getFilePattern()); } if ($this->runnerFactory->create()->hasDetailedProgress()) { $options[] = '--detailed-progress'; } $options = array_merge($options, $this->doBuildRunnerOptions()); $this->testTargetRepository->walkOnResources(function ($resource, $index, TestTargetRepository $testTargetRepository) use(&$options) { $options[] = escapeshellarg($resource); }); return $options; }