phpunitHow to use the PHPUnit Framework ExceptionWrapper?
PHPUnit Framework ExceptionWrapper is a utility class that helps to wrap exceptions thrown by the code under test. It provides a convenient way to catch and verify exceptions.
Example code
try {
// code that throws an exception
} catch (Exception $e) {
$wrapper = new PHPUnit_Framework_ExceptionWrapper($e);
// do something with the wrapper
}
The code above will catch any exception thrown by the code under test and wrap it in a PHPUnit_Framework_ExceptionWrapper object. This object can then be used to verify the exception, for example:
$this->assertEquals('My expected exception message', $wrapper->getMessage());
The PHPUnit_Framework_ExceptionWrapper class provides the following methods:
- getMessage(): Returns the exception message
- getCode(): Returns the exception code
- getFile(): Returns the file name where the exception was thrown
- getLine(): Returns the line number where the exception was thrown
- getTrace(): Returns the stack trace
- getPrevious(): Returns the previous exception
Helpful links
More of Phpunit
- How to order tests with PHPUnit?
- How to disable color output in PHPUnit?
- How to mock an interface in PHPUnit?
- How to mock a class in PHPUnit?
- How to use a listener with PHPUnit?
- How to install PHPUnit with a PHAR file?
- How to skip a PHPUnit test?
- How to show warnings in PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to use hooks in PHPUnit?
See more codes...