3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Wraps Exceptions thrown by code under test.
14 * Re-instantiates Exceptions thrown by user-space code to retain their original
15 * class names, properties, and stack traces (but without arguments).
17 * Unlike PHPUnit_Framework_Exception, the complete stack of previous Exceptions
20 * @since Class available since Release 4.3.0
22 class PHPUnit_Framework_ExceptionWrapper extends PHPUnit_Framework_Exception
30 * @var PHPUnit_Framework_ExceptionWrapper|null
35 * @param Throwable|Exception $e
37 public function __construct($e)
39 // PDOException::getCode() is a string.
40 // @see http://php.net/manual/en/class.pdoexception.php#95812
41 parent::__construct($e->getMessage(), (int) $e->getCode());
43 $this->classname = get_class($e);
44 $this->file = $e->getFile();
45 $this->line = $e->getLine();
47 $this->serializableTrace = $e->getTrace();
49 foreach ($this->serializableTrace as $i => $call) {
50 unset($this->serializableTrace[$i]['args']);
53 if ($e->getPrevious()) {
54 $this->previous = new self($e->getPrevious());
61 public function getClassname()
63 return $this->classname;
67 * @return PHPUnit_Framework_ExceptionWrapper
69 public function getPreviousWrapped()
71 return $this->previous;
77 public function __toString()
79 $string = PHPUnit_Framework_TestFailure::exceptionToString($this);
81 if ($trace = PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
82 $string .= "\n" . $trace;
85 if ($this->previous) {
86 $string .= "\nCaused by\n" . $this->previous;