|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Pitchart\Phlunit\Checks\HttpResponse; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\Assert; |
|
7
|
|
|
use Pitchart\Phlunit\Checks\FluentCheck; |
|
8
|
|
|
use Pitchart\Phlunit\Checks\Mixin\ConstraintCheck; |
|
9
|
|
|
use Pitchart\Phlunit\Checks\Mixin\FluentChecks; |
|
10
|
|
|
use Pitchart\Phlunit\Checks\Mixin\TypeCheck; |
|
11
|
|
|
use Pitchart\Phlunit\Checks\Mixin\WithMessage; |
|
12
|
|
|
use Pitchart\Phlunit\Constraint\HttpResponse\HeaderContains; |
|
13
|
|
|
use Pitchart\Phlunit\Constraint\HttpResponse\HeaderIsEqualTo; |
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class HttpHeaderCheck |
|
18
|
|
|
* |
|
19
|
|
|
* @package Pitchart\Phlunit\Checks\HttpResponse |
|
20
|
|
|
* |
|
21
|
|
|
* @author Julien VITTE <[email protected]> |
|
22
|
|
|
* |
|
23
|
|
|
* @template THeader |
|
24
|
|
|
* @implements FluentCheck<THeader> |
|
25
|
|
|
*/ |
|
26
|
|
|
class HttpHeaderCheck implements FluentCheck |
|
27
|
|
|
{ |
|
28
|
1 |
|
use FluentChecks, TypeCheck, WithMessage, ConstraintCheck; |
|
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var ResponseInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $response; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $header; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* HttpHeaderCheck constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param ResponseInterface $response |
|
43
|
|
|
* @param string $header |
|
44
|
|
|
* @param array $value |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function __construct(ResponseInterface $response, string $header) |
|
47
|
|
|
{ |
|
48
|
1 |
|
$this->response = $response; |
|
49
|
1 |
|
$this->header = $header; |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function isEqualTo(string $headerValue, string $message = ''): self |
|
53
|
|
|
{ |
|
54
|
1 |
|
Assert::assertThat($this->response, new HeaderIsEqualTo($this->header, $headerValue), $message); |
|
55
|
1 |
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function contains(string $headerPart, string $message = ''): self |
|
59
|
|
|
{ |
|
60
|
1 |
|
Assert::assertThat($this->response, new HeaderContains($this->header, $headerPart), $message); |
|
61
|
1 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|