/** * Gets the formatter from world and register it into the reporter */ protected function setFormatter() { $formatterOption = $this->_world->getOption('formatter'); $formatter = $this->getFormatterFactory()->create($formatterOption, $this->_world->getReporter()); $this->_world->getReporter()->addFormatter($formatter); }
/** * Runs tests based on the given array. * * @param \Stagehand\TestRunner\TestSuite\PHPSpecTestSuite $suite */ public function run($suite) { $options = array(); $options['specFile'] = $suite; $options['c'] = $this->terminal->shouldColor(); $options['failfast'] = $this->shouldStopOnFailure(); $reporter = new Reporter(); if ($this->hasDetailedProgress()) { $reporter->addFormatter(new TerminatableFormatter(new DocumentationFormatter($reporter))); } else { $reporter->addFormatter(new TerminatableFormatter(new ProgressFormatter($reporter))); } if ($this->shouldNotify()) { $notificationFormatter = new NotificationFormatter($reporter); $reporter->addFormatter(new TerminatableFormatter($notificationFormatter)); } if ($this->hasJUnitXMLFile()) { $junitXMLFormatter = new JUnitXMLFormatter($reporter); $junitXMLFormatter->setJUnitXMLWriter($this->createJUnitXMLWriter()); $junitXMLFormatter->setTestSuite($suite); $junitXMLFormatter->setTestTargetRepository($this->testTargetRepository); $reporter->addFormatter(new TerminatableFormatter($junitXMLFormatter)); } $world = new World(); $world->setOptions($options); $world->setReporter($reporter); $oldErrorHandler = set_error_handler(function () { }); restore_error_handler(); $exampleRunner = new ExampleRunner(); $exampleRunner->setExampleFactory(new ExampleFactory($this->testTargetRepository)); $runner = new \PHPSpec\Runner\Cli\Runner(); $runner->setLoader(new SpecLoaderFactory()); $runner->setExampleRunner($exampleRunner); $runner->run($world); $reporter->notify(new ReporterEvent('termination', '', '')); if (!is_null($oldErrorHandler)) { set_error_handler($oldErrorHandler); } if ($this->shouldNotify()) { $this->notification = $notificationFormatter->getNotification(); } }
/** * Loads the bootstrap file if specified in the options */ public function bootstrap(\PHPSpec\World $world) { $bootstrapFile = $world->getOption('bootstrap'); if (empty($bootstrapFile)) { return; } if (!file_exists($bootstrapFile) || !is_readable($bootstrapFile)) { throw new CliError('Cannot load specified bootstrap file: ' . $bootstrapFile); } include $bootstrapFile; }