/** * * @param ExampleEvent $event * * @throws \PhpSpec\Exception\Example\StopOnFailureException */ public function afterExample(ExampleEvent $event) { if (!$this->io->isStopOnFailureEnabled()) { return; } if ($event->getResult() === ExampleEvent::FAILED || $event->getResult() === ExampleEvent::BROKEN) { throw new StopOnFailureException('Example failed', 0, null, $event->getResult()); } }
/** * @param ExampleEvent $event * * @throws \PhpSpec\Exception\Example\StopOnFailureException */ public function afterExample(ExampleEvent $event) { if (!$this->input->hasOption('stop-on-failure') || !$this->input->getOption('stop-on-failure')) { return; } if ($event->getResult() === ExampleEvent::FAILED || $event->getResult() === ExampleEvent::BROKEN) { throw new StopOnFailureException('Example failed'); } }
/** * @param ExampleEvent $event * @param PresenterInterface $presenter * * @return ReportFailedItem|ReportPassedItem|ReportPendingItem */ public function create(ExampleEvent $event, PresenterInterface $presenter = null) { switch ($event->getResult()) { case ExampleEvent::PASSED: return new ReportPassedItem($this->template, $event); case ExampleEvent::PENDING: return new ReportPendingItem($this->template, $event); case ExampleEvent::FAILED: case ExampleEvent::BROKEN: return new ReportFailedItem($this->template, $event, $presenter); default: $this->invalidResultException($event->getResult()); } }
/** * @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); }
/** * * @param ExampleEvent $event */ public function afterExample(ExampleEvent $event) { $io = $this->getIO(); $eventsCount = $this->getStatisticsCollector()->getEventsCount(); if ($eventsCount === 1) { $io->writeln(); } switch ($event->getResult()) { case ExampleEvent::PASSED: $io->write('<passed>.</passed>'); break; case ExampleEvent::PENDING: $io->write('<pending>P</pending>'); break; case ExampleEvent::SKIPPED: $io->write('<skipped>S</skipped>'); break; case ExampleEvent::FAILED: $io->write('<failed>F</failed>'); break; case ExampleEvent::BROKEN: $io->write('<broken>B</broken>'); break; } if ($eventsCount % 50 === 0) { $length = strlen((string) $this->examplesCount); $format = sprintf(' %%%dd / %%%dd', $length, $length); $io->write(sprintf($format, $eventsCount, $this->examplesCount)); if ($eventsCount !== $this->examplesCount) { $io->writeLn(); } } }
function it_outputs_monkey_when_example_is_pending(IO $io, ExampleEvent $event) { $event->getResult()->willReturn(ExampleEvent::PENDING); $this->outputEmoji($event); $io->write(mb_convert_encoding('🙉', 'UTF-8', 'HTML-ENTITIES'))->shouldHaveBeenCalled(); $io->write(' ')->shouldHaveBeenCalled(); }
public function afterExample(ExampleEvent $event) { $type = $this->map[$event->getResult()]; $this->addResult($type, $event->getSpecification(), $event->getTitle()); if ($this->coverage) { $this->coverage->stop(); } }
function it_should_creates_result_event(ExampleEvent $exampleEvent, SpecificationNode $specificationNode, CodeCoverageSession $coverageSession) { $exampleEvent->getResult()->shouldBeCalled()->willReturn(ExampleEvent::PASSED); $specificationNode->getTitle()->shouldBeCalled()->willReturn('SomeSpesification'); $coverageSession->stop()->shouldBeCalled(); $this->afterExample($exampleEvent); $this->getResults()->shouldHaveCount(1); }
public function afterExample(ExampleEvent $event) { $this->globalResult = max($this->globalResult, $event->getResult()); switch ($event->getResult()) { case ExampleEvent::PASSED: $this->passedEvents[] = $event; break; case ExampleEvent::PENDING: $this->pendingEvents[] = $event; break; case ExampleEvent::FAILED: $this->failedEvents[] = $event; break; case ExampleEvent::BROKEN: $this->brokenEvents[] = $event; break; } }
function it_outputs_the_progress_every_50_examples(ExampleEvent $exampleEvent, SuiteEvent $suiteEvent, ConsoleIO $io, StatisticsCollector $stats) { $exampleEvent->getResult()->willReturn(ExampleEvent::PASSED); $suiteEvent->getSuite()->willReturn(range(1, 100)); $stats->getEventsCount()->willReturn(50); $this->beforeSuite($suiteEvent); $this->afterExample($exampleEvent); $io->write(' 50 / 100')->shouldHaveBeenCalled(); }
function it_stores_a_testcase_node_after_failed_example_run(ExampleEvent $event, SpecificationNode $specification, \ReflectionClass $refClass) { $event->getResult()->willReturn(ExampleEvent::FAILED); $event->getTitle()->willReturn('example title'); $event->getTime()->willReturn(1337); $event->getException()->willReturn(new ExceptionStub('Something went wrong', 'Exception trace')); $event->getSpecification()->willReturn($specification); $specification->getClassReflection()->willReturn($refClass); $refClass->getName()->willReturn('Acme\\Foo\\Bar'); $this->afterExample($event); $this->getTestCaseNodes()->shouldReturn(array('<testcase name="example title" time="1337" classname="Acme\\Foo\\Bar" status="failed">' . "\n" . '<failure type="spec\\PhpSpec\\Formatter\\ExceptionStub" message="Something went wrong" />' . "\n" . '<system-err>' . "\n" . '<![CDATA[' . "\n" . 'Exception trace' . "\n" . ']]>' . "\n" . '</system-err>' . "\n" . '</testcase>')); }
function it_stores_a_testcase_node_after_skipped_example_run(ExampleEvent $event, SpecificationNode $specification, \ReflectionClass $refClass) { $event->getResult()->willReturn(ExampleEvent::SKIPPED); $event->getTitle()->willReturn('example title'); $event->getTime()->willReturn(1337); $event->getException()->willReturn(new SkippingException('zog zog')); $event->getSpecification()->willReturn($specification); $specification->getClassReflection()->willReturn($refClass); $refClass->getName()->willReturn('Acme\\Foo\\Bar'); $this->afterExample($event); // skipped tag is escaped because a skipped tag is also registered in the console formatter $this->getTestCaseNodes()->shouldReturn(array('<testcase name="example title" time="1337.000000" classname="Acme\\Foo\\Bar" status="skipped">' . "\n" . '\\<skipped><![CDATA[ skipped: zog zog ]]>\\</skipped>' . "\n" . '</testcase>')); }
public function outputEmoji(ExampleEvent $event) { switch ($event->getResult()) { case ExampleEvent::PASSED: $this->io->write($this->encodeChar('😄')); break; case ExampleEvent::FAILED: $this->io->write($this->encodeChar('💩')); break; case ExampleEvent::BROKEN: $this->io->write($this->encodeChar('🔥')); break; case ExampleEvent::SKIPPED: $this->io->write($this->encodeChar('🙈')); break; case ExampleEvent::PENDING: $this->io->write($this->encodeChar('🙉')); break; } $this->io->write(' '); }
/** * @param ExampleEvent $event */ public function afterExample(ExampleEvent $event) { $io = $this->getIO(); $output = ob_get_clean(); if ($output) { $io->writeln($this->teamCityMessage("testStdOut", array("name" => $event->getTitle(), "out" => "Test Output\n>>>>>>>>>>>\n{$output}\n<<<<<<<<<<<\n"))); } switch ($event->getResult()) { case ExampleEvent::PASSED: break; case ExampleEvent::PENDING: $io->writeln($this->teamCityMessage('testIgnored', array('name' => $event->getTitle(), 'details' => $event->getMessage()))); break; case ExampleEvent::FAILED: $io->writeln($this->teamCityMessage('testFailed', array('name' => $event->getTitle(), 'message' => "Failed Test\n\n" . $event->getMessage(), 'details' => $event->getException()->getTraceAsString()))); break; case ExampleEvent::BROKEN: $io->writeln($this->teamCityMessage('testFailed', array('name' => $event->getTitle(), 'message' => "Broken Test\n\n" . $event->getMessage(), 'details' => $event->getException()->getTraceAsString()))); break; } $io->writeln($this->teamCityMessage('testFinished', array('name' => $event->getTitle()))); }
function it_does_not_throw_an_exception_when_an_example_breaks_and_option_is_not_set(ExampleEvent $event) { $event->getResult()->willReturn(ExampleEvent::BROKEN); $this->afterExample($event); }
/** * @param ExampleNode $example * * @return int */ public function run(ExampleNode $example) { $startTime = microtime(true); $this->dispatcher->dispatch('beforeExample', new ExampleEvent($example)); try { $this->executeExample($example->getSpecification()->getClassReflection()->newInstance(), $example); $status = ExampleEvent::PASSED; $exception = null; } catch (ExampleException\PendingException $e) { $status = ExampleEvent::PENDING; $exception = $e; } catch (ExampleException\SkippingException $e) { $status = ExampleEvent::SKIPPED; $exception = $e; } catch (ProphecyException\Prediction\PredictionException $e) { $status = ExampleEvent::FAILED; $exception = $e; } catch (ExampleException\FailureException $e) { $status = ExampleEvent::FAILED; $exception = $e; } catch (Exception $e) { $status = ExampleEvent::BROKEN; $exception = $e; } if ($exception instanceof PhpSpecException) { $exception->setCause($example->getFunctionReflection()); } $runTime = microtime(true) - $startTime; $this->dispatcher->dispatch('afterExample', $event = new ExampleEvent($example, $runTime, $status, $exception)); return $event->getResult(); }
/** * {@inheritdoc} */ public function afterExample(ExampleEvent $event) { $testCaseNode = sprintf('<testcase name="%s" time="%s" classname="%s" status="%s"', $event->getTitle(), $event->getTime(), $event->getSpecification()->getClassReflection()->getName(), $this->jUnitStatuses[$event->getResult()]); $this->exampleStatusCounts[$event->getResult()]++; if (in_array($event->getResult(), array(ExampleEvent::BROKEN, ExampleEvent::FAILED))) { $exception = $event->getException(); $testCaseNode .= sprintf('>' . "\n" . '<%s type="%s" message="%s" />' . "\n" . '<system-err>' . "\n" . '<![CDATA[' . "\n" . '%s' . "\n" . ']]>' . "\n" . '</system-err>' . "\n" . '</testcase>', $this->resultTags[$event->getResult()], get_class($exception), htmlspecialchars($exception->getMessage()), $exception->getTraceAsString()); } else { $testCaseNode .= ' />'; } $this->testCaseNodes[] = $testCaseNode; }
function it_creates_a_ReportBrokenItem(ExampleEvent $event, Presenter $presenter) { $event->getResult()->willReturn(ExampleEvent::BROKEN); $this->create($event, $presenter)->shouldHaveType('PhpSpec\\Formatter\\Html\\ReportFailedItem'); }
public function afterExample(ExampleEvent $event) { ExampleEvent::PASSED == $event->getResult() ? $this->afterPassedExample($event) : $this->afterNotPassedExample($event); }
protected function printException(ExampleEvent $event, $depth = null) { $io = $this->getIO(); if (null === ($exception = $event->getException())) { return; } $depth = $depth ?: 8; $message = $this->getPresenter()->presentException($exception, $io->isVerbose()); if (ExampleEvent::FAILED === $event->getResult()) { $io->writeln(sprintf('<failed>%s</failed>', lcfirst($message)), $depth); } elseif (ExampleEvent::PENDING === $event->getResult()) { $io->writeln(sprintf('<pending>%s</pending>', lcfirst($message)), $depth); } elseif (ExampleEvent::SKIPPED === $event->getResult()) { $io->writeln(sprintf('<skipped>%s</skipped>', lcfirst($message)), $depth); } else { $io->writeln(sprintf('<broken>%s</broken>', lcfirst($message)), $depth); } }
function let(ExampleEvent $failingExample, ExampleEvent $passingExample) { $failingExample->getResult()->willReturn(ExampleEvent::FAILED); $passingExample->getResult()->willReturn(ExampleEvent::PASSED); }
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(); }