function it_does_not_prompt_when_wrong_exception_is_thrown(IO $io, ExampleEvent $event, SuiteEvent $suiteEvent) { $event->getException()->willReturn(new RuntimeException()); $this->afterExample($event); $this->afterSuite($suiteEvent); $io->askConfirmation(Argument::any())->shouldNotHaveBeenCalled(); }
function it_does_not_prompt_to_generate_when_there_was_an_exception_of_the_wrong_type(IO $io, ExampleEvent $exampleEvent, SuiteEvent $suiteEvent, \InvalidArgumentException $otherException) { $exampleEvent->getException()->willReturn($otherException); $this->afterExample($exampleEvent); $this->afterSuite($suiteEvent); $io->askConfirmation(Argument::any())->shouldNotHaveBeenCalled(); }
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(); }
/** * * @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(); } } }
public function afterExample(ExampleEvent $exampleEvent) { $exception = $exampleEvent->getException(); if (!$exception instanceof NotEqualException) { return; } if ($exception->getActual() !== null) { return; } if (is_object($exception->getExpected()) || is_array($exception->getExpected()) || is_resource($exception->getExpected())) { return; } if (!$this->lastMethodCallEvent) { return; } $class = get_class($this->lastMethodCallEvent->getSubject()); $method = $this->lastMethodCallEvent->getMethod(); if (!$this->methodAnalyser->methodIsEmpty($class, $method)) { return; } $key = $class . '::' . $method; if (!array_key_exists($key, $this->nullMethods)) { $this->nullMethods[$key] = array('class' => $this->methodAnalyser->getMethodOwnerName($class, $method), 'method' => $method, 'expected' => array()); } $this->nullMethods[$key]['expected'][] = $exception->getExpected(); }
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); }
function it_identifies_a_resource_model_type(ExampleEvent $exampleEvent, ClassNotFoundException $exception, SuiteEvent $suiteEvent, $configGenerator) { $exampleEvent->getException()->willReturn($exception); $exception->getClassname()->willReturn('Vendor_Module_Model_Resource_Foo'); $this->getClassNameAfterExample($exampleEvent); $this->createXmlAfterSuite($suiteEvent); $configGenerator->generateElement('resource_model', 'Vendor_Module')->shouldHavebeenCalled(); }
function it_should_call_afterCurrentExample(ExampleEvent $example) { $currentExample = new CurrentExampleTracker(); $currentExample->setCurrentExample(null); $example->getTitle()->willReturn(null); $this->afterCurrentExample($example); $example->getTitle()->shouldNotHaveBeenCalled(); }
/** * * @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()); } }
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); }
/** * @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'); } }
function it_writes_a_fail_message_for_a_failing_example(Template $template, ExampleEvent $event, Presenter $presenter) { $event->getTitle()->willReturn(self::EVENT_TITLE); $event->getMessage()->willReturn(self::EVENT_MESSAGE); $event->getBacktrace()->willReturn(self::$BACKTRACE); $event->getException()->willReturn(new \Exception()); $template->render(Template::DIR . '/Template/ReportFailed.html', array('title' => self::EVENT_TITLE, 'message' => self::EVENT_MESSAGE, 'backtrace' => self::BACKTRACE, 'code' => self::CODE, 'index' => 1, 'specification' => 1))->shouldBeCalled(); $presenter->presentException(Argument::cetera())->willReturn(self::CODE); $this->write(1); }
public function afterExample(ExampleEvent $event) { if (null === ($exception = $event->getException())) { return; } if (!$exception instanceof MethodNotFoundException) { return; } $this->methods[get_class($exception->getSubject()) . '::' . $exception->getMethodName()] = $exception->getArguments(); }
/** * @param ExampleEvent $event */ public function afterExample(ExampleEvent $event) { if (null === ($exception = $event->getException())) { return; } if (!$exception instanceof PhpSpecClassException && !$exception instanceof ProphecyClassException) { return; } $this->classes[$exception->getClassname()] = true; }
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()); }
/** * @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(); }
/** * * @return string */ private function formatBacktrace() { $backtrace = ''; foreach ($this->event->getBacktrace() as $step) { if (isset($step['line']) && isset($step['file'])) { $backtrace .= "#{$step['line']} {$step['file']}"; $backtrace .= "<br />"; $backtrace .= PHP_EOL; } } return rtrim($backtrace, "<br />" . PHP_EOL); }
public function afterExample(ExampleEvent $event) { if (null === ($exception = $event->getException())) { return; } if (!$exception instanceof MethodNotFoundException) { return; } $classname = get_class($exception->getSubject()); $methodName = $exception->getMethodName(); $this->methods[$classname . '::' . $methodName] = $exception->getArguments(); $this->checkIfMethodNameAllowed($methodName); }
/** * @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()); } }
public function getClassNameAfterExample(ExampleEvent $event) { if (null === ($exception = $event->getException())) { return; } if (!$exception instanceof PhpSpecClassException && !$exception instanceof ProphecyClassException) { return; } $className = $exception->getClassname(); if (strlen($className)) { $parts = explode('_', $className); if (!isset($parts[0]) || !isset($parts[1])) { return; } $this->classNames[$className] = $parts[0] . '_' . $parts[1]; } }
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(); }
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; } }
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(' '); }
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>')); }
/** * @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->presenter->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); } 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); } 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(); }
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 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); }
function it_warns_if_a_method_name_is_wrong(ExampleEvent $event, SuiteEvent $suiteEvent, ConsoleIO $io, NameChecker $nameChecker) { $exception = new MethodNotFoundException('Error', new DoubleOfInterface(), 'throw'); $event->getException()->willReturn($exception); $nameChecker->isNameValid('throw')->willReturn(false); $io->writeBrokenCodeBlock("I cannot generate the method 'throw' for you because it is a reserved keyword", 2)->shouldBeCalled(); $io->askConfirmation(Argument::any())->shouldNotBeCalled(); $this->afterExample($event); $this->afterSuite($suiteEvent); }
/** * {@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; }