/** * Build a title by navigating a test's tree * * @param string $color * @param TestInterface $test * @return string */ protected function getTitle($color, TestInterface $test) { $description = ""; $test->forEachNodeTopDown(function (TestInterface $node) use(&$description) { $description .= " " . $node->getDescription(); }); return $this->color($color, trim($description)); }
/** * Add behaviors relevant when a test is executed * * @param TestInterface $test * @return void */ public function onTestStart(TestInterface $test) { $scope = $test->getScope(); $behavior = new StateBehavior($test); $scope->use($behavior); }
/** * Handle the test.start event. */ public function onTestStart(TestInterface $test) { $this->coverage->start($test->getTitle()); }
/** * Put the test into a pending state. Halts test execution when * called * * @throws \Peridot\Core\Exception\PendingException */ public function pend() { $this->test->setPending(true); throw new PendingException(); }
/** * Output a test failure. * * @param int $errorNumber * @param TestInterface $test * @param $exception */ protected function outputError($errorNumber, TestInterface $test, \Exception $exception) { $this->output->writeln(sprintf(" %d)%s:", $errorNumber, $test->getTitle())); $message = sprintf(" %s", str_replace(PHP_EOL, PHP_EOL . " ", $exception->getMessage())); $this->output->writeln($this->color('error', $message)); $trace = $exception instanceof PeridotException ? $exception->getTraceString() : $exception->getTraceAsString(); $trace = preg_replace('/^#/m', " #", $trace); $this->output->writeln($this->color('muted', $trace)); }
/** * Output a test failure. * * @param int $errorNumber * @param TestInterface $test * @param $exception - an exception like interface with ->getMessage(), ->getTraceAsString() */ protected function outputError($errorNumber, TestInterface $test, $exception) { $this->output->writeln(sprintf(" %d)%s:", $errorNumber, $test->getTitle())); $message = sprintf(" %s", str_replace(PHP_EOL, PHP_EOL . " ", $exception->getMessage())); $this->output->writeln($this->color('error', $message)); }