Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
ResponseContainsHeader
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fail
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 failureDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toString
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 matches
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php declare(strict_types=1);
2/*
3 * This file is part of Aplus Framework Testing Library.
4 *
5 * (c) Natan Felles <natanfelles@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10namespace Framework\Testing\Constraints;
11
12use PHPUnit\Framework\Constraint\Constraint;
13use PHPUnit\Framework\ExpectationFailedException;
14use SebastianBergmann\Comparator\ComparisonFailure;
15
16/**
17 * Class ResponseContainsHeader.
18 *
19 * @package testing
20 */
21final class ResponseContainsHeader extends Constraint
22{
23    private string $string;
24
25    public function __construct(string $string)
26    {
27        $this->string = $string;
28    }
29
30    protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) : void
31    {
32        $failureDescription = \sprintf(
33            'Failed asserting that Response %s',
34            $this->failureDescription($other)
35        );
36        if ( ! empty($description)) {
37            $failureDescription = $description . "\n" . $failureDescription;
38        }
39        throw new ExpectationFailedException(
40            $failureDescription,
41            $comparisonFailure
42        );
43    }
44
45    protected function failureDescription($other) : string
46    {
47        return $this->toString();
48    }
49
50    public function toString() : string
51    {
52        return \sprintf(
53            "contains header '%s'.",
54            $this->string
55        );
56    }
57
58    protected function matches(mixed $other) : bool
59    {
60        return $other !== null;
61    }
62}