public function afterExample(ExampleEvent $event) { $io = $this->getIO(); $line = $event->getExample()->getFunctionReflection()->getStartLine(); $depth = 2; $title = preg_replace('/^it /', '', $event->getExample()->getTitle()); $io->write(sprintf('<lineno>%4d</lineno> ', $line)); switch ($event->getResult()) { case ExampleEvent::PASSED: $io->write(sprintf('<passed>✔ %s</passed>', $title), $depth - 1); break; case ExampleEvent::PENDING: $io->write(sprintf('<pending>- %s</pending>', $title), $depth - 1); break; case ExampleEvent::SKIPPED: $io->write(sprintf('<skipped>? %s</skipped>', $title), $depth - 1); break; case ExampleEvent::FAILED: $io->write(sprintf('<failed>✘ %s</failed>', $title), $depth - 1); break; case ExampleEvent::BROKEN: $io->write(sprintf('<broken>! %s</broken>', $title), $depth - 1); break; } $this->printSlowTime($event); $io->writeln(); $this->printException($event); }
/** * @param ExampleEvent $event * @param string $type */ protected function printSpecificException(ExampleEvent $event, $type) { $title = str_replace('\\', DIRECTORY_SEPARATOR, $event->getSpecification()->getTitle()); $message = $this->getPresenter()->presentException($event->getException(), $this->io->isVerbose()); foreach (explode("\n", wordwrap($title, $this->io->getBlockWidth(), "\n", true)) as $line) { $this->io->writeln(sprintf('<%s-bg>%s</%s-bg>', $type, str_pad($line, $this->io->getBlockWidth()), $type)); } $this->io->writeln(sprintf('<lineno>%4d</lineno> <%s>- %s</%s>', $event->getExample()->getFunctionReflection()->getStartLine(), $type, $event->getExample()->getTitle(), $type)); $this->io->writeln(sprintf('<%s>%s</%s>', $type, lcfirst($message), $type), 6); $this->io->writeln(); }
/** * @param ExampleEvent $event */ protected function printException(ExampleEvent $event) { if (null === ($exception = $event->getException())) { return; } $title = str_replace('\\', DIRECTORY_SEPARATOR, $event->getSpecification()->getTitle()); $title = str_pad($title, 50, ' ', STR_PAD_RIGHT); $message = $this->getPresenter()->presentException($exception, $this->io->isVerbose()); if ($exception instanceof PendingException) { $this->io->writeln(sprintf('<pending-bg>%s</pending-bg>', $title)); $this->io->writeln(sprintf('<lineno>%4d</lineno> <pending>- %s</pending>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle())); $this->io->writeln(sprintf('<pending>%s</pending>', lcfirst($message)), 6); $this->io->writeln(); } elseif ($exception instanceof SkippingException) { if ($this->io->isVerbose()) { $this->io->writeln(sprintf('<skipped-bg>%s</skipped-bg>', $title)); $this->io->writeln(sprintf('<lineno>%4d</lineno> <skipped>? %s</skipped>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle())); $this->io->writeln(sprintf('<skipped>%s</skipped>', lcfirst($message)), 6); $this->io->writeln(); } } elseif (ExampleEvent::FAILED === $event->getResult()) { $this->io->writeln(sprintf('<failed-bg>%s</failed-bg>', $title)); $this->io->writeln(sprintf('<lineno>%4d</lineno> <failed>✘ %s</failed>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle())); $this->io->writeln(sprintf('<failed>%s</failed>', lcfirst($message)), 6); $this->io->writeln(); } else { $this->io->writeln(sprintf('<broken-bg>%s</broken-bg>', $title)); $this->io->writeln(sprintf('<lineno>%4d</lineno> <broken>! %s</broken>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle())); $this->io->writeln(sprintf('<broken>%s</broken>', lcfirst($message)), 6); $this->io->writeln(); } }
/** * @param ExampleEvent $event */ public function afterExample(ExampleEvent $event) { $this->examplesCount++; $desc = sprintf(self::DESC, $this->currentSpecificationTitle, preg_replace('/^its? /', '', $event->getExample()->getTitle())); switch ($event->getResult()) { case ExampleEvent::PASSED: $result = sprintf(self::OK, $this->examplesCount) . $desc; break; case ExampleEvent::PENDING: $message = $this->getResultData($event, $event->getResult()); $result = sprintf(self::NOT_OK, $this->examplesCount) . $desc . $message; break; case ExampleEvent::SKIPPED: $message = sprintf(self::SKIP, $this->getResultData($event)); $result = sprintf(self::OK, $this->examplesCount) . $desc . $message; break; case ExampleEvent::BROKEN: case ExampleEvent::FAILED: $message = $this->getResultData($event, $event->getResult()); $result = sprintf(self::NOT_OK, $this->examplesCount) . $desc . "\n" . $message; break; default: $message = $this->getResultData($event, self::UNDEFINED_RESULT); $result = sprintf(self::NOT_OK, $this->examplesCount) . $desc . "\n" . $message; } $this->getIO()->writeln($result); }
public function beforeExample(ExampleEvent $event) { $example = $event->getExample(); $name = strtr('%spec% => %example%', array('%spec%' => $example->getSpecification()->getClassReflection()->getName(), '%example%' => $example->getTitle())); if ($this->coverage) { $this->coverage->start($name); } }
public function beforeExample(ExampleEvent $event) { $specFilename = $event->getSpecification()->getClassReflection()->getFileName(); $specClass = $event->getSpecification()->getClassReflection()->getName(); $exampleName = $event->getExample()->getFunctionReflection()->getName(); $this->getIO()->writeln($this->teamCityMessage('testStarted', array('name' => $event->getTitle(), 'captureStandardOutput' => 'false', 'locationHint' => "file://{$specFilename}::\\{$specClass}::{$exampleName}"))); ob_start(); }
public function beforeExample(ExampleEvent $event) { if (!$this->enabled) { return; } $example = $event->getExample(); $name = strtr('%spec%::%example%', array('%spec%' => $example->getSpecification()->getClassReflection()->getName(), '%example%' => $example->getFunctionReflection()->getName())); $this->coverage->start($name); }
function it_should_start_coverage(CodeCoverageSession $coverageSession, ExampleEvent $event, ExampleNode $example, SpecificationNode $specificationNode) { $reflection = new \ReflectionClass($this); $event->getExample()->willReturn($example); $example->getSpecification()->willReturn($specificationNode); $example->getTitle()->willReturn('title'); $specificationNode->getClassReflection()->willReturn($reflection); $coverageSession->start(__CLASS__ . ' => title')->shouldBeCalled(); $this->beforeExample($event); }
public function beforeExample(ExampleEvent $event) { if (!$this->enabled) { return; } $example = $event->getExample(); $resource = $example->getSpecification()->getResource(); $this->coverage->filter()->setWhitelistedFiles([]); $this->coverage->filter()->addFileToWhitelist($resource->getSrcFilename()); $this->coverage->start($resource->getSrcClassname()); }
function it_outputs_exceptions_for_failed_examples(SuiteEvent $event, ExampleEvent $pendingEvent, ConsoleIO $io, StatisticsCollector $stats, SpecificationNode $specification, ExampleNode $example) { $example->getLineNumber()->willReturn(37); $example->getTitle()->willReturn('it tests something'); $pendingEvent->getException()->willReturn(new PendingException()); $pendingEvent->getSpecification()->willReturn($specification); $pendingEvent->getExample()->willReturn($example); $stats->getEventsCount()->willReturn(1); $stats->getFailedEvents()->willReturn(array()); $stats->getBrokenEvents()->willReturn(array()); $stats->getPendingEvents()->willReturn(array($pendingEvent)); $stats->getSkippedEvents()->willReturn(array()); $stats->getTotalSpecs()->willReturn(1); $stats->getCountsHash()->willReturn(array('passed' => 0, 'pending' => 1, 'skipped' => 0, 'failed' => 0, 'broken' => 0)); $this->afterSuite($event); $expected = '<lineno> 37</lineno> <pending>- it tests something</pending>'; $io->writeln($expected)->shouldHaveBeenCalled(); }
function it_outputs_undefined_progress_on_afterexample_event(SpecificationEvent $specEvent, ExampleEvent $exampleEvent, ExampleNode $example, SpecificationNode $spec, IO $io, StatisticsCollector $stats) { $specEvent->getSpecification()->willReturn($spec); $exampleEvent->getExample()->willReturn($example); $example->getTitle()->willReturn('foobar'); $exampleEvent->getResult()->willReturn(999); $spec->getTitle()->willReturn('spec1'); $this->beforeSpecification($specEvent); $this->afterExample($exampleEvent); $expected = "not ok 1 - spec1: foobar\n ---\n message: 'The example result type was unknown to formatter'\n severity: fail\n ..."; $io->writeln($expected)->shouldHaveBeenCalled(); }
private function title(ExampleEvent $event) { return $event->getExample()->getTitle(); }