/** * Asserts we have a formatter and create one if we don't */ private function makeSureWeHaveAFormatter() { if (!count($this->_reporter->getFormatters())) { $this->_world->setOptions(array('formatter' => 'p')); $this->setFormatter(); } }
/** * 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(); } }