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 * Base class for all PHPUnit Framework exceptions.
14 * Ensures that exceptions thrown during a test run do not leave stray
17 * Every Exception contains a stack trace. Each stack frame contains the 'args'
18 * of the called function. The function arguments can contain references to
19 * instantiated objects. The references prevent the objects from being
20 * destructed (until test results are eventually printed), so memory cannot be
23 * With enabled process isolation, test results are serialized in the child
24 * process and unserialized in the parent process. The stack trace of Exceptions
25 * may contain objects that cannot be serialized or unserialized (e.g., PDO
26 * connections). Unserializing user-space objects from the child process into
27 * the parent would break the intended encapsulation of process isolation.
29 * @see http://fabien.potencier.org/article/9/php-serialization-stack-traces-and-exceptions
30 * @since Class available since Release 3.4.0
32 class PHPUnit_Framework_Exception extends RuntimeException implements PHPUnit_Exception
37 protected $serializableTrace;
39 public function __construct($message = '', $code = 0, Exception $previous = null)
41 parent::__construct($message, $code, $previous);
43 $this->serializableTrace = $this->getTrace();
44 foreach ($this->serializableTrace as $i => $call) {
45 unset($this->serializableTrace[$i]['args']);
50 * Returns the serializable trace (without 'args').
54 public function getSerializableTrace()
56 return $this->serializableTrace;
62 public function __toString()
64 $string = PHPUnit_Framework_TestFailure::exceptionToString($this);
66 if ($trace = PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
67 $string .= "\n" . $trace;
73 public function __sleep()
75 return array_keys(get_object_vars($this));