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\Constraint;
11
 
12
use function get_class;
13
use function sprintf;
14
use PHPUnit\Util\Filter;
15
use Throwable;
16
 
17
/**
18
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
19
 */
20
final class Exception extends Constraint
21
{
22
    /**
23
     * @var string
24
     */
25
    private $className;
26
 
27
    public function __construct(string $className)
28
    {
29
        $this->className = $className;
30
    }
31
 
32
    /**
33
     * Returns a string representation of the constraint.
34
     */
35
    public function toString(): string
36
    {
37
        return sprintf(
38
            'exception of type "%s"',
39
            $this->className
40
        );
41
    }
42
 
43
    /**
44
     * Evaluates the constraint for parameter $other. Returns true if the
45
     * constraint is met, false otherwise.
46
     *
47
     * @param mixed $other value or object to evaluate
48
     */
49
    protected function matches($other): bool
50
    {
51
        return $other instanceof $this->className;
52
    }
53
 
54
    /**
55
     * Returns the description of the failure.
56
     *
57
     * The beginning of failure messages is "Failed asserting that" in most
58
     * cases. This method should return the second part of that sentence.
59
     *
60
     * @param mixed $other evaluated value or object
61
     */
62
    protected function failureDescription($other): string
63
    {
64
        if ($other !== null) {
65
            $message = '';
66
 
67
            if ($other instanceof Throwable) {
68
                $message = '. Message was: "' . $other->getMessage() . '" at'
69
                    . "\n" . Filter::getFilteredStacktrace($other);
70
            }
71
 
72
            return sprintf(
73
                'exception of type "%s" matches expected exception "%s"%s',
74
                get_class($other),
75
                $this->className,
76
                $message
77
            );
78
        }
79
 
80
        return sprintf(
81
            'exception of type "%s" is thrown',
82
            $this->className
83
        );
84
    }
85
}