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 sprintf;
13
use Throwable;
14
 
15
/**
16
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
17
 */
18
final class ExceptionCode extends Constraint
19
{
20
    /**
21
     * @var int|string
22
     */
23
    private $expectedCode;
24
 
25
    /**
26
     * @param int|string $expected
27
     */
28
    public function __construct($expected)
29
    {
30
        $this->expectedCode = $expected;
31
    }
32
 
33
    public function toString(): string
34
    {
35
        return 'exception code is ';
36
    }
37
 
38
    /**
39
     * Evaluates the constraint for parameter $other. Returns true if the
40
     * constraint is met, false otherwise.
41
     *
42
     * @param Throwable $other
43
     */
44
    protected function matches($other): bool
45
    {
46
        return (string) $other->getCode() === (string) $this->expectedCode;
47
    }
48
 
49
    /**
50
     * Returns the description of the failure.
51
     *
52
     * The beginning of failure messages is "Failed asserting that" in most
53
     * cases. This method should return the second part of that sentence.
54
     *
55
     * @param mixed $other evaluated value or object
56
     *
57
     * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
58
     */
59
    protected function failureDescription($other): string
60
    {
61
        return sprintf(
62
            '%s is equal to expected exception code %s',
63
            $this->exporter()->export($other->getCode()),
64
            $this->exporter()->export($this->expectedCode)
65
        );
66
    }
67
}