Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
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
namespace PHPUnit\Framework;
11
 
12
use function array_keys;
13
use function get_object_vars;
14
use PHPUnit\Util\Filter;
15
use RuntimeException;
16
use Throwable;
17
 
18
/**
19
 * Base class for all PHPUnit Framework exceptions.
20
 *
21
 * Ensures that exceptions thrown during a test run do not leave stray
22
 * references behind.
23
 *
24
 * Every Exception contains a stack trace. Each stack frame contains the 'args'
25
 * of the called function. The function arguments can contain references to
26
 * instantiated objects. The references prevent the objects from being
27
 * destructed (until test results are eventually printed), so memory cannot be
28
 * freed up.
29
 *
30
 * With enabled process isolation, test results are serialized in the child
31
 * process and unserialized in the parent process. The stack trace of Exceptions
32
 * may contain objects that cannot be serialized or unserialized (e.g., PDO
33
 * connections). Unserializing user-space objects from the child process into
34
 * the parent would break the intended encapsulation of process isolation.
35
 *
36
 * @see http://fabien.potencier.org/article/9/php-serialization-stack-traces-and-exceptions
37
 *
38
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
39
 */
40
class Exception extends RuntimeException implements \PHPUnit\Exception
41
{
42
    /**
43
     * @var array
44
     */
45
    protected $serializableTrace;
46
 
47
    public function __construct($message = '', $code = 0, Throwable $previous = null)
48
    {
49
        parent::__construct($message, $code, $previous);
50
 
51
        $this->serializableTrace = $this->getTrace();
52
 
53
        foreach (array_keys($this->serializableTrace) as $key) {
54
            unset($this->serializableTrace[$key]['args']);
55
        }
56
    }
57
 
58
    public function __toString(): string
59
    {
60
        $string = TestFailure::exceptionToString($this);
61
 
62
        if ($trace = Filter::getFilteredStacktrace($this)) {
63
            $string .= "\n" . $trace;
64
        }
65
 
66
        return $string;
67
    }
68
 
69
    public function __sleep(): array
70
    {
71
        return array_keys(get_object_vars($this));
72
    }
73
 
74
    /**
75
     * Returns the serializable trace (without 'args').
76
     */
77
    public function getSerializableTrace(): array
78
    {
79
        return $this->serializableTrace;
80
    }
81
}