715c55e4b5dbf2e49dd7701599949296ea27308e
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Exception.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Base class for all PHPUnit Framework exceptions.
13  *
14  * Ensures that exceptions thrown during a test run do not leave stray
15  * references behind.
16  *
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
21  * freed up.
22  *
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.
28  *
29  * @see http://fabien.potencier.org/article/9/php-serialization-stack-traces-and-exceptions
30  * @since Class available since Release 3.4.0
31  */
32 class PHPUnit_Framework_Exception extends RuntimeException implements PHPUnit_Exception
33 {
34     /**
35      * @var array
36      */
37     protected $serializableTrace;
38
39     public function __construct($message = '', $code = 0, Exception $previous = null)
40     {
41         parent::__construct($message, $code, $previous);
42
43         $this->serializableTrace = $this->getTrace();
44         foreach ($this->serializableTrace as $i => $call) {
45             unset($this->serializableTrace[$i]['args']);
46         }
47     }
48
49     /**
50      * Returns the serializable trace (without 'args').
51      *
52      * @return array
53      */
54     public function getSerializableTrace()
55     {
56         return $this->serializableTrace;
57     }
58
59     /**
60      * @return string
61      */
62     public function __toString()
63     {
64         $string = PHPUnit_Framework_TestFailure::exceptionToString($this);
65
66         if ($trace = PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
67             $string .= "\n" . $trace;
68         }
69
70         return $string;
71     }
72
73     public function __sleep()
74     {
75         return array_keys(get_object_vars($this));
76     }
77 }