exceptionToString() public static méthode

Returns a description for an exception.
public static exceptionToString ( Exception $e ) : string
$e Exception
Résultat string
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $class = get_class($test);
     $message = $this->escape(PHPUnit_Framework_TestFailure::exceptionToString($e));
     $trace = $this->escape($e->getTraceAsString());
     echo "##teamcity[testFailed type='failure' name='{$class}.{$test->getName()}' message='{$message}'" . " details='{$trace}']\n";
 }
Exemple #2
0
 /**
  * @return string
  */
 public function __toString()
 {
     $string = PHPUnit_Framework_TestFailure::exceptionToString($this);
     if ($trace = PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
         $string .= "\n" . $trace;
     }
     return $string;
 }
 protected function printDefectTrace(\PHPUnit_Framework_TestFailure $defect)
 {
     $this->write($this->formatExceptionMsg($defect->getExceptionAsString()));
     $trace = \PHPUnit_Util_Filter::getFilteredStacktrace($defect->thrownException());
     if (!empty($trace)) {
         $this->write("\n" . $trace);
     }
     $exception = $defect->thrownException()->getPrevious();
     while ($exception) {
         $this->write("\nCaused by\n" . \PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . \PHPUnit_Util_Filter::getFilteredStacktrace($e));
         $exception = $exception->getPrevious();
     }
 }
Exemple #4
0
 /**
  * A failure occurred.
  *
  * @param PHPUnit_Framework_Test                 $test
  * @param PHPUnit_Framework_AssertionFailedError $e
  * @param float                                  $time
  */
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->writeNotOk($test, 'Failure');
     $message = explode("\n", PHPUnit_Framework_TestFailure::exceptionToString($e));
     $diagnostic = array('message' => $message[0], 'severity' => 'fail');
     if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
         $cf = $e->getComparisonFailure();
         if ($cf !== null) {
             $diagnostic['data'] = array('got' => $cf->getActual(), 'expected' => $cf->getExpected());
         }
     }
     $yaml = new Symfony\Component\Yaml\Dumper();
     $this->write(sprintf("  ---\n%s  ...\n", $yaml->dump($diagnostic, 2, 2)));
 }
    public function testInvalidMediaType()
    {
        $mediaType = 'application/pdf';
        self::assertFalse($this->constraint->evaluate($mediaType, '', true));
        try {
            $this->constraint->evaluate($mediaType);
            self::fail('Expected ExpectationFailedException to be thrown');
        } catch (ExpectationFailedException $e) {
            self::assertEquals(<<<EOF
Failed asserting that 'application/pdf' is an allowed media type (application/json, application/xml, text/xml, text/html).

EOF
, TestFailure::exceptionToString($e));
        }
    }
 /**
  * @Then /^It should (fail|pass) with:$/
  */
 public function assertFailOrPassWith($success, PyStringNode $data)
 {
     if ('fail' === $success) {
         assertNotEquals(0, $this->return);
     } else {
         assertEquals(0, $this->return);
     }
     $realData = preg_replace('/\\# \\/.*BehatBundle\\//', '# ', (string) $this->output);
     try {
         assertEquals((string) $data, $realData);
     } catch (\Exception $e) {
         $diff = \PHPUnit_Framework_TestFailure::exceptionToString($e);
         throw new \Exception($diff, $e->getCode(), $e);
     }
 }
    public function testInvalidHeaderType()
    {
        $headers = ['Content-Type' => 'application/json'];
        self::assertFalse($this->constraint->evaluate($headers, '', true));
        try {
            $this->constraint->evaluate($headers);
            self::fail('Expected ExpectationFailedException to be thrown');
        } catch (ExpectationFailedException $e) {
            self::assertEquals(<<<EOF
Failed asserting that {"Content-Type":"application\\/json"} is valid.
[etag] The property etag is required

EOF
, TestFailure::exceptionToString($e));
        }
    }
 /**
  * @return string
  */
 public function __toString()
 {
     $string = \PHPUnit_Framework_TestFailure::exceptionToString($this);
     $e = $this->getWrappedException();
     $string .= "\n  Request: " . $this->requestToString($e) . "\n" . "  HTTP status Code: " . $e->getHttpStatusCode() . "\n" . "  Is transient: " . ($e->isTransient() ? 'true' : 'false') . "\n" . "  Code: " . $e->getCode() . "\n" . "  Error Subcode: " . $e->getErrorSubcode() . "\n" . "  Error User Title: " . $e->getErrorUserTitle() . "\n" . "  Error User Message: " . $e->getErrorUserMessage() . "\n";
     if ($e->getErrorBlameFieldSpecs()) {
         $string .= "  Error Blame Fields: " . $this->blameFieldSpecsToString() . "\n";
     }
     if ($trace = \PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
         $string .= "\n" . $trace;
     }
     if ($this->previous) {
         $string .= "\nCaused by\n" . $this->previous;
     }
     return $string;
 }
Exemple #9
0
 /**
  * Print test
  *
  * @param array $test
  * @param null $name
  * @return string
  */
 public function printTest(array $test, $name = NULL)
 {
     $testName = $name ? $name : $test['testName'];
     $roundPrecision = $test['time'] < 10 ? 2 : 0;
     $result = '';
     $result .= '<div class="test ' . $this->getStatusName($test['status']) . '">';
     $result .= '<div class="duration">' . round($test['time'], $roundPrecision) . 's</div>';
     $result .= '<h2>' . $this->shorten($testName) . '</h2>';
     $result .= '<div class="description">';
     if (!empty($test['description'])) {
         $result .= '<p>' . nl2br($test['description']) . '</p>';
     }
     $result .= '</div><!-- description -->';
     if (isset($test['loggedTestSteps'])) {
         $result .= $this->renderTestSteps($test['loggedTestSteps']);
     }
     if (is_array($test['info'])) {
         $result .= '<ul class="info">';
         foreach ($test['info'] as $info) {
             $result .= '<li>' . $info . '</li>';
         }
         $result .= '</ul>';
     }
     $result .= '<div class="content">';
     if ($test['exception'] instanceof Exception) {
         $e = $test['exception'];
         /* @var $e Exception */
         $result .= '<div class="exception">';
         $result .= '<i>' . nl2br($this->escape(PHPUnit_Util_Filter::getFilteredStacktrace($e))) . '</i>' . "<br />\n";
         $result .= '<pre>' . $this->escape(PHPUnit_Framework_TestFailure::exceptionToString($e)) . '</pre>';
         $result .= '</div><!-- exception -->';
     }
     if (isset($test['screenshots'])) {
         $result .= '<div class="screenshots">';
         $result .= $this->printScreenshots($test['screenshots']);
         $result .= '</div><!-- screenshots -->';
     }
     $result .= '</div><!-- content -->';
     $result .= '</div><!-- test -->';
     return $result;
 }
    public function testInvalidSchema()
    {
        $response = <<<JSON
[
  {
    "id": 123456789
  }
]
JSON;
        $response = json_decode($response);
        self::assertFalse($this->constraint->evaluate($response, '', true));
        try {
            $this->constraint->evaluate($response);
            self::fail('Expected ExpectationFailedException to be thrown');
        } catch (ExpectationFailedException $e) {
            self::assertEquals(<<<EOF
Failed asserting that [{"id":123456789}] is valid.
[name] The property name is required

EOF
, TestFailure::exceptionToString($e));
        }
    }
Exemple #11
0
 /**
  * Method which generalizes addError() and addFailure()
  *
  * @param PHPUnit_Framework_Test $test
  * @param Exception              $e
  * @param float                  $time
  * @param string                 $type
  */
 private function doAddFault(PHPUnit_Framework_Test $test, Exception $e, $time, $type)
 {
     if ($this->currentTestCase === null) {
         return;
     }
     if ($test instanceof PHPUnit_Framework_SelfDescribing) {
         $buffer = $test->toString() . "\n";
     } else {
         $buffer = '';
     }
     $buffer .= PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($e);
     $fault = $this->document->createElement($type, PHPUnit_Util_XML::prepareString($buffer));
     $fault->setAttribute('type', get_class($e));
     $this->currentTestCase->appendChild($fault);
 }
Exemple #12
0
 protected function printScenarioFail(ScenarioDriven $failedTest, $fail)
 {
     $feature = $failedTest->getFeature();
     $failToString = \PHPUnit_Framework_TestFailure::exceptionToString($fail);
     $failMessage = $this->message($failedTest->getSignature())->style('bold')->append(' (')->append(codecept_relative_path($failedTest->getFileName()))->append(')');
     if ($fail instanceof \PHPUnit_Framework_SkippedTest || $fail instanceof \PHPUnit_Framework_IncompleteTest) {
         $this->printSkippedTest($feature, $failedTest->getFileName(), $failToString);
         return;
     }
     if ($feature) {
         $failMessage->prepend("Failed to {$feature} in ");
     }
     $failMessage->writeln();
     $failedStep = "";
     foreach ($failedTest->getScenario()->getSteps() as $step) {
         if ($step->hasFailed()) {
             $failedStep = (string) $step;
             break;
         }
     }
     $this->printException($fail, $failedStep);
     $this->printScenarioTrace($failedTest, $failToString);
     if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_DEBUG) {
         $this->printExceptionTrace($fail);
         return;
     }
     if (!$fail instanceof \PHPUnit_Framework_AssertionFailedError) {
         $this->printExceptionTrace($fail);
         return;
     }
 }
Exemple #13
0
 /**
  * A failure occurred.
  *
  * @param PHPUnit_Framework_Test                 $test
  * @param PHPUnit_Framework_AssertionFailedError $e
  * @param float                                  $time
  */
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     if ($this->currentTestCase !== null) {
         if (!$test instanceof PHPUnit_Framework_Warning) {
             if ($test instanceof PHPUnit_Framework_SelfDescribing) {
                 $buffer = $test->toString() . "\n";
             } else {
                 $buffer = '';
             }
             $buffer .= PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($e);
             $failure = $this->document->createElement('failure', PHPUnit_Util_XML::prepareString($buffer));
             $failure->setAttribute('type', get_class($e));
             $this->currentTestCase->appendChild($failure);
             $this->testSuiteFailures[$this->testSuiteLevel]++;
         }
     }
 }
 /**
  * @throws PHPUnit_Framework_Exception
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 public function verify()
 {
     if ($this->invocationMatcher === null) {
         throw new PHPUnit_Framework_Exception('No invocation matcher is set');
     }
     if ($this->methodNameMatcher === null) {
         throw new PHPUnit_Framework_Exception('No method matcher is set');
     }
     try {
         $this->invocationMatcher->verify();
         if ($this->parametersMatcher === null) {
             $this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters();
         }
         $invocationIsAny = get_class($this->invocationMatcher) === 'PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount';
         $invocationIsNever = get_class($this->invocationMatcher) === 'PHPUnit_Framework_MockObject_Matcher_InvokedCount' && $this->invocationMatcher->isNever();
         if (!$invocationIsAny && !$invocationIsNever) {
             $this->parametersMatcher->verify();
         }
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         throw new PHPUnit_Framework_ExpectationFailedException(sprintf("Expectation failed for %s when %s.\n%s", $this->methodNameMatcher->toString(), $this->invocationMatcher->toString(), PHPUnit_Framework_TestFailure::exceptionToString($e)));
     }
 }
Exemple #15
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);
     }
 }
 protected function printScenarioFail(ScenarioDriven $failedTest, $fail)
 {
     $failToString = \PHPUnit_Framework_TestFailure::exceptionToString($fail);
     $failedStep = "";
     foreach ($failedTest->getScenario()->getSteps() as $step) {
         if ($step->hasFailed()) {
             $failedStep = (string) $step;
             break;
         }
     }
     $this->printException($fail, $failedStep);
     $this->printScenarioTrace($failedTest, $failToString);
     if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_DEBUG) {
         $this->printExceptionTrace($fail);
         return;
     }
     if (!$fail instanceof \PHPUnit_Framework_AssertionFailedError) {
         $this->printExceptionTrace($fail);
         return;
     }
 }
 /**
  * @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);
     }
 }
Exemple #18
0
 public function printFail(\Codeception\Event\Fail $e)
 {
     $failedTest = $e->getTest();
     $fail = $e->getFail();
     $failToString = \PHPUnit_Framework_TestFailure::exceptionToString($fail);
     $feature = $failedTest->getScenario()->getFeature();
     $this->output->put("\nCouldn't {$feature}");
     $this->output->put(" ({$failedTest->getFilename()})\n");
     $trace = array_reverse($failedTest->getTrace());
     $length = $i = count($trace);
     $last = array_shift($trace);
     if (!method_exists($last, 'getHumanizedAction')) {
         if (!$this->debug) {
             $this->output->writeln($failToString);
             return;
         }
         $this->output->writeln($this->printException('not an action', $fail));
         return;
     }
     $action = $last->getHumanizedAction();
     if (strpos($action, "am") === 0) {
         $action = 'become' . substr($action, 2);
     }
     // it's exception
     if (!$fail instanceof \PHPUnit_Framework_AssertionFailedError) {
         if ($this->debug) {
             $this->printException($last->getAction(), $fail);
         } else {
             $this->output->writeln('to see the stack trace run this test with --debug option');
         }
         return;
     }
     // it's assertion
     if (strpos($action, "don't") === 0) {
         $action = substr($action, 6);
         $this->output->writeln("\nGuy unexpectedly managed to {$action} {$failToString}");
     } else {
         $this->output->writeln("Guy couldn't {$action} {$failToString}");
     }
     $this->output->writeln("  {$i}. (!{$last}!)");
     foreach ($trace as $step) {
         $i--;
         $this->output->writeln("  {$i}. " . $step);
         if ($length - $i - 1 >= $this->traceLength) {
             break;
         }
     }
     $this->output->writeln("");
 }
Exemple #19
0
 /**
  * On not successful
  * In case of an exeception $this->tearDown() will be called before processing this method anyways
  *
  * @throws PHPUnit_Framework_SyntheticError
  * @param Exception $e
  * @return void
  */
 protected function onNotSuccessfulTest(Exception $e)
 {
     if (!($e instanceof PHPUnit_Framework_IncompleteTestError || $e instanceof PHPUnit_Framework_SkippedTestError) && $this->captureScreenshotOnFailure) {
         try {
             $this->takeScreenshot(get_class($e), PHPUnit_Framework_TestFailure::exceptionToString($e), Menta_Util_Screenshot::TYPE_ERROR, $e->getTrace());
         } catch (Exception $screenshotException) {
             // if there's an exception while taking a screenshot because a test was not successful. That's bad luck :)
             throw new PHPUnit_Framework_SyntheticError($e->getMessage() . ' (AND: Exception while taking screenshot: ' . $screenshotException->getMessage() . ')', $e->getCode(), $e->getFile(), $e->getLine(), $e->getTrace());
         }
     }
     parent::onNotSuccessfulTest($e);
 }
Exemple #20
0
    protected function printScenarioFail(ScenarioDriven $failedTest, $fail)
    {
        $feature = $failedTest->getFeature();
        $failToString = \PHPUnit_Framework_TestFailure::exceptionToString($fail);
        $failMessage = $this->message($failedTest->getSignature())
            ->style('bold')
            ->append(' (')
            ->append($failedTest->getFileName())
            ->append(')');

        if ($fail instanceof \PHPUnit_Framework_SkippedTest
            or $fail instanceof \PHPUnit_Framework_IncompleteTest
        ) {
            $this->printSkippedTest($feature, $failedTest->getFileName(), $failToString);
            return;
        }
        if ($feature) {
            $failMessage->prepend("Failed to $feature in ");
        }
        $failMessage->writeln();
        $this->printScenarioTrace($failedTest, $failToString);
        if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_DEBUG) {
            $this->printException($fail);
            return;
        }
        if (!$fail instanceof \PHPUnit_Framework_AssertionFailedError) {
            $this->printException($fail);
            return;
        }
    }
Exemple #21
0
 public function testFailureTraversableNotContains2()
 {
     $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_TraversableContains('foo'));
     try {
         $constraint->fail(array('foo'), 'custom message', TRUE);
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("custom message\nFailed asserting that an array does not contain <string:foo>.\n", PHPUnit_Framework_TestFailure::exceptionToString($e));
         return;
     }
     $this->fail();
 }
Exemple #22
0
</div>
  <div class="desc"><span class="assertions">Assertions: <b><?php 
echo (int) $test['assertions'];
?>
</b>,</span><span class="problems">Problems: <b><?php 
echo count($test['deprecated']) + count($test['errors']);
?>
</b>,</span><span class="time">Executed in <?php 
printf('%06f', $test['time']);
?>
 seconds.</span></div>
  
  <div class="expand-button"></div>
  <div class="more">
    <div class="result"><pre><?php 
echo isset($test['result']['e']) ? htmlentities(PHPUnit_Framework_TestFailure::exceptionToString($test['result']['e']) . PHPUnit_Util_Filter::getFilteredStacktrace($test['result']['e'], FALSE)) : '';
?>
</pre></div>
    <?php 
if ($test['errors'] !== null) {
    foreach ($test['errors'] as $error) {
        $e = $error['e'];
        include 'exception.php';
    }
}
?>
    <?php 
if ($test['deprecated'] !== null) {
    foreach ($test['deprecated'] as $deprecated) {
        include 'deprecated.php';
    }
 /**
  * Creates a user-presentable string describing the given exception.
  *
  * @param $exception \Exception The exception to describe
  */
 protected function exceptionToString(\Exception $exception)
 {
     if ($exception instanceof \PHPUnit_Framework_Exception) {
         // PHPUnit assertion exceptions do not include expected / observed info in their
         // messages, but expect the test listeners to format that info like the following
         // (see e.g. PHPUnit_TextUI_ResultPrinter::printDefectTrace)
         return trim(\PHPUnit_Framework_TestFailure::exceptionToString($exception));
     }
     if ($this->parameters->get('verbose')) {
         return trim($exception);
     }
     return trim($exception->getMessage());
 }
 /**
  * Checks whether last command output contains provided string.
  *
  * @Then the output should contain:
  *
  * @param   Behat\Gherkin\Node\PyStringNode $text   PyString text instance
  */
 public function theOutputShouldContain(PyStringNode $text)
 {
     $text = strtr($text, array('\'\'\'' => '"""', '%PATH%' => realpath(getcwd())));
     // windows path fix
     if ('/' !== DIRECTORY_SEPARATOR) {
         $text = preg_replace_callback('/ features\\/[^\\n ]+/', function ($matches) {
             return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
         }, (string) $text);
         $text = preg_replace_callback('/\\<span class\\="path"\\>features\\/[^\\<]+/', function ($matches) {
             return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
         }, (string) $text);
         $text = preg_replace_callback('/\\+[fd] [^ ]+/', function ($matches) {
             return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
         }, (string) $text);
     }
     try {
         assertContains((string) $text, $this->output);
     } catch (Exception $e) {
         $diff = PHPUnit_Framework_TestFailure::exceptionToString($e);
         throw new Exception($diff, $e->getCode(), $e);
     }
 }
Exemple #25
0
 /**
  * Skipped test.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  Exception              $e
  * @param  float                  $time
  */
 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
 {
     $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE);
     $this->storeResult(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $time, $message);
     $this->currentTestSuccess = FALSE;
 }
    /**
     * @covers PHPUnit_Framework_Constraint_SameSize
     * @covers PHPUnit_Framework_Constraint_Not
     * @covers PHPUnit_Framework_Assert::logicalNot
     * @covers PHPUnit_Framework_TestFailure::exceptionToString
     */
    public function testConstraintNotSameSizeFailing()
    {
        $constraint = PHPUnit_Framework_Assert::logicalNot(new PHPUnit_Framework_Constraint_SameSize(array(1, 2)));
        try {
            $constraint->evaluate(array(3, 4));
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
            $this->assertEquals(<<<EOF
Failed asserting that actual size 2 does not match expected size 2.

EOF
, PHPUnit_Framework_TestFailure::exceptionToString($e));
            return;
        }
        $this->fail();
    }
Exemple #27
0
        $text = preg_replace_callback('/\\+[fd] [^ ]+/', function ($matches) {
            return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
        }, (string) $text);
    }
    try {
        assertContains((string) $text, $world->output);
    } catch (Exception $e) {
        $diff = PHPUnit_Framework_TestFailure::exceptionToString($e);
        throw new Exception($diff, $e->getCode(), $e);
    }
});
$steps->Then('/^the output should not contain:$/', function ($world, $text) {
    // windows path fix
    if ('/' !== DIRECTORY_SEPARATOR) {
        $text = preg_replace_callback('/ features\\/[^\\n ]+/', function ($matches) {
            return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
        }, (string) $text);
    }
    try {
        assertNotContains((string) $text, $world->output);
    } catch (Exception $e) {
        $diff = PHPUnit_Framework_TestFailure::exceptionToString($e);
        throw new Exception($diff, $e->getCode(), $e);
    }
});
$steps->Then('/^display last command exit code$/', function ($world) {
    $world->printDebug("`" . $world->command . "`  =>  " . $world->return);
});
$steps->Then('/^display last command output$/', function ($world) {
    $world->printDebug("`" . $world->command . "`:\n" . $world->output);
});
Exemple #28
0
 /**
  * @param  PHPUnit_Framework_TestFailure $defect
  */
 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
 {
     $this->write($defect->getExceptionAsString() . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($defect->thrownException()));
     $e = $defect->thrownException()->getPrevious();
     while ($e) {
         $this->write("\nCaused by\n" . PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($e));
         $e = $e->getPrevious();
     }
 }
    /**
     * @covers PHPUnit_Framework_Constraint_Exception
     * @covers PHPUnit_Framework_TestFailure::exceptionToString
     */
    public function testConstraintException()
    {
        $constraint = new PHPUnit_Framework_Constraint_Exception('FoobarException');
        $exception = new DummyException('Test');
        $stackTrace = $exception->getTraceAsString();
        try {
            $constraint->evaluate($exception);
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
            $this->assertEquals(<<<EOF
Failed asserting that exception of type "DummyException" matches expected exception "FoobarException". Message was: "Test" at
{$stackTrace}.

EOF
, PHPUnit_Framework_TestFailure::exceptionToString($e));
            return;
        }
        $this->fail();
    }
Exemple #30
0
 /**
  * @param Exception $e
  *
  * @return string
  */
 private static function getDetails(Exception $e)
 {
     $stackTrace = PHPUnit_Util_Filter::getFilteredStacktrace($e);
     $previous = $e->getPrevious();
     while ($previous) {
         $stackTrace .= "\nCaused by\n" . PHPUnit_Framework_TestFailure::exceptionToString($previous) . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($previous);
         $previous = $previous->getPrevious();
     }
     return ' ' . str_replace("\n", "\n ", $stackTrace);
 }