A TestFailure collects a failed test together with the caught exception.
@package PHPUnit @subpackage Framework @author Sebastian Bergmann <sebastian@phpunit.de> @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de> @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License @link http://www.phpunit.de/ @since Class available since Release 2.0.0
Expanded class hierarchy of PHPUnit_Framework_TestFailure
class PHPUnit_Framework_TestFailure {
/**
* @var PHPUnit_Framework_Test
*/
protected $failedTest;
/**
* @var Exception
*/
protected $thrownException;
/**
* Constructs a TestFailure with the given test and exception.
*
* @param PHPUnit_Framework_Test $failedTest
* @param Exception $thrownException
*/
public function __construct(PHPUnit_Framework_Test $failedTest, Exception $thrownException) {
$this->failedTest = $failedTest;
$this->thrownException = $thrownException;
}
/**
* Returns a short description of the failure.
*
* @return string
*/
public function toString() {
return sprintf('%s: %s', $this->failedTest
->toString(), $this->thrownException
->getMessage());
}
/**
* Returns a description for the thrown exception.
*
* @return string
* @since Method available since Release 3.4.0
*/
public function getExceptionAsString() {
return self::exceptionToString($this->thrownException);
}
/**
* Returns a description for an exception.
*
* @param Exception $e
* @return string
* @since Method available since Release 3.2.0
*/
public static function exceptionToString(Exception $e) {
if ($e instanceof PHPUnit_Framework_SelfDescribing) {
$buffer = $e
->toString();
if ($e instanceof PHPUnit_Framework_ExpectationFailedException && $e
->getComparisonFailure()) {
$buffer = $buffer . "\n" . $e
->getComparisonFailure()
->getDiff();
}
if (!empty($buffer)) {
$buffer = trim($buffer) . "\n";
}
}
else {
if ($e instanceof PHPUnit_Framework_Error) {
$buffer = $e
->getMessage() . "\n";
}
else {
$buffer = get_class($e) . ': ' . $e
->getMessage() . "\n";
}
}
return $buffer;
}
/**
* Gets the failed test.
*
* @return Test
*/
public function failedTest() {
return $this->failedTest;
}
/**
* Gets the thrown exception.
*
* @return Exception
*/
public function thrownException() {
return $this->thrownException;
}
/**
* Returns the exception's message.
*
* @return string
*/
public function exceptionMessage() {
return $this
->thrownException()
->getMessage();
}
/**
* Returns TRUE if the thrown exception
* is of type AssertionFailedError.
*
* @return boolean
*/
public function isFailure() {
return $this
->thrownException() instanceof PHPUnit_Framework_AssertionFailedError;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PHPUnit_Framework_TestFailure:: |
protected | property | ||
PHPUnit_Framework_TestFailure:: |
protected | property | ||
PHPUnit_Framework_TestFailure:: |
public | function | Returns the exception's message. | |
PHPUnit_Framework_TestFailure:: |
public static | function | Returns a description for an exception. | |
PHPUnit_Framework_TestFailure:: |
public | function | Gets the failed test. | |
PHPUnit_Framework_TestFailure:: |
public | function | Returns a description for the thrown exception. | |
PHPUnit_Framework_TestFailure:: |
public | function | Returns TRUE if the thrown exception is of type AssertionFailedError. | |
PHPUnit_Framework_TestFailure:: |
public | function | Gets the thrown exception. | |
PHPUnit_Framework_TestFailure:: |
public | function | Returns a short description of the failure. | |
PHPUnit_Framework_TestFailure:: |
public | function | Constructs a TestFailure with the given test and exception. |