Exemple #1
0
 public function printFail(\Codeception\Event\Fail $e)
 {
     $failedTest = $e->getTest();
     $fail = $e->getFail();
     if ($fail instanceof \PHPUnit_Framework_SelfDescribing) {
         $failToString = \PHPUnit_Framework_TestFailure::exceptionToString($fail);
     } else {
         $failToString = sprintf("[%s]\n%s", get_class($fail), $fail->getMessage());
     }
     $feature = $failedTest->getScenario()->getFeature();
     if ($e->getCount()) {
         $this->output->put($e->getCount() . ") ");
     }
     // skip test
     // Sample Message: create user in CreateUserCept.php is not ready for release
     if ($fail instanceof \PHPUnit_Framework_SkippedTest or $fail instanceof \PHPUnit_Framework_IncompleteTest) {
         if ($feature) {
             $this->output->put("[[{$feature}]] in ");
         }
         $this->output->put($failedTest->getFilename());
         if ($failToString) {
             $this->output->put(" is " . $failToString);
         }
         $this->output->writeln("\n");
         return;
     }
     if ($feature) {
         $this->output->put("Couldn't [[{$feature}]] in ");
     }
     $this->output->writeln('((' . $failedTest->getFilename() . '))');
     $trace = array_reverse($failedTest->getTrace());
     $length = $i = count($trace);
     $last = array_shift($trace);
     if (!method_exists($last, 'getHumanizedAction')) {
         $this->printException($fail);
         return;
     }
     $action = $last->getHumanizedAction();
     if (strpos($action, "am") === 0) {
         $action = 'become' . substr($action, 2);
     }
     // it's exception
     if (!$fail instanceof \PHPUnit_Framework_AssertionFailedError) {
         $this->printException($fail);
         return;
     }
     // it's assertion
     if (strpos($action, "don't") === 0) {
         $action = substr($action, 6);
         $this->output->writeln("Guy unexpectedly managed to {$action}:\n{$failToString}");
     } else {
         $this->output->writeln("Guy couldn't {$action}: {$failToString}");
     }
     $this->output->writeln("Scenario Steps:");
     $this->output->writeln("{$i}. (!{$last}!)");
     foreach ($trace as $step) {
         $i--;
         $this->output->writeln("{$i}. " . $step);
         if ($length - $i - 1 >= $this->traceLength) {
             break;
         }
     }
     if ($this->debug) {
         $this->printException($fail);
     }
 }
Exemple #2
0
 public function printFail(\Codeception\Event\Fail $e)
 {
     $failedTest = $e->getTest();
     $fail = $e->getFail();
     $this->output->write($e->getCount() . ") ");
     if ($e->getTest() instanceof ScenarioDriven) {
         $this->printScenarioFail($failedTest, $fail);
         return;
     }
     $failToString = \PHPUnit_Framework_TestFailure::exceptionToString($fail);
     $this->message(get_class($failedTest))->append('::')->append($failedTest->getName())->style('bold')->append("\n")->append($failToString)->writeln();
     $this->printException($fail);
 }