/** * @param \PHPUnit_Framework_Test $test * @param \Exception $e * @param float $time * @param string $failureOrError */ protected function writeFailureOrError(\PHPUnit_Framework_Test $test, \Exception $e, $time, $failureOrError) { $testIsArtificial = false; if (!$this->testStarted) { $this->startTest($test); $testIsArtificial = true; } if ($test instanceof \PHPUnit_Framework_SelfDescribing) { $message = $test->toString() . "\n\n"; } else { $message = ''; } $message .= \PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n"; if ($test instanceof \PHPUnit_Framework_Warning) { $testClass = new \ReflectionClass($this->currentTestClassName); $file = $testClass->getFileName(); $line = 1; } elseif ($test instanceof \PHPUnit_Framework_WarningTestCase && preg_match('/^No tests found in class "([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)"\\.$/', $test->getMessage(), $matches)) { $testClass = new \ReflectionClass($this->currentTestClassName); $file = $testClass->getFileName(); $line = 1; } else { list($file, $line) = FailureTrace::findFileAndLineOfFailureOrError($this->testTargetRepository->getRequiredSuperTypes(), $e, new \ReflectionClass($test)); } $trace = \PHPUnit_Util_Filter::getFilteredStacktrace($e, true); $this->junitXMLWriter->{'write' . $failureOrError}($message . $trace, get_class($e), $file, $line, $message); if ($testIsArtificial) { $this->endTest($test, 0); } }
/** * Collects all test cases included in the given file. * * @param string $file */ public function collectTestCasesFromFile($file) { if (!$this->testTargetRepository->shouldTreatFileAsTest($file)) { return; } foreach ($this->findNewClasses($file) as $newClass) { $collectingTypeFactory = $this->collectingTypeFactory->create($newClass, $this->testTargetRepository->getRequiredSuperTypes()); if ($collectingTypeFactory->isTest()) { $this->collectTestCase($newClass); } } }
/** * @param \PHPSpec\Runner\ReporterEvent $reporterEvent * @param string $failureOrError */ protected function renderFailureOrError(ReporterEvent $reporterEvent, $failureOrError) { list($file, $line) = FailureTrace::findFileAndLineOfFailureOrError($this->testTargetRepository->getRequiredSuperTypes(), $reporterEvent->exception, new \ReflectionClass($this->testSuite->getExampleGroupClass($this->currentExampleGroupName))); $failureTrace = FailureTrace::buildFailureTrace($reporterEvent->exception->getTrace()); $this->junitXMLWriter->{'write' . $failureOrError}($reporterEvent->message . PHP_EOL . PHP_EOL . $failureTrace, get_class($reporterEvent->exception), $file, $line, $reporterEvent->message); }