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(); }
/** * @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(); } }
public function afterExample(ExampleEvent $event) { $type = $this->map[$event->getResult()]; $this->addResult($type, $event->getSpecification(), $event->getTitle()); if ($this->coverage) { $this->coverage->stop(); } }
/** * @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(); }
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>')); }
function let(SpecificationNode $specificationNode, ExampleEvent $exampleEvent, ServiceContainer $container, CodeCoverageSession $coverageSession) { $r = new \ReflectionClass(__CLASS__); $specificationNode->getClassReflection()->willReturn($r); $specificationNode->getTitle()->willReturn('Specification'); $exampleEvent->getSpecification()->willReturn($specificationNode); $exampleEvent->getTitle()->willReturn('it should do something'); $this->cwd = getcwd(); chdir(sys_get_temp_dir()); $container->get('coverage.session')->willReturn($coverageSession); $this->setCoverageRunner($coverageSession); $this->load($container); }
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(); }
/** * {@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; }
public function afterExample(ExampleEvent $event) { $this->logger->logExample($event->getSpecification()->getTitle(), $event->getTitle(), $event->getTime()); }