| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\HttpFoundation\Test\Constraint; |
| 13 |
|
| 14 |
use PHPUnit\Framework\Constraint\Constraint; |
| 15 |
use Symfony\Component\HttpFoundation\Request; |
| 16 |
use Symfony\Component\HttpFoundation\Response; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
> |
| 22 |
|
| 23 |
final class ResponseFormatSame extends Constraint |
| 24 |
{ |
| 25 |
public function __construct( |
| 26 |
private Request $request, |
| 27 |
private ?string $format, |
| 28 |
private readonly bool $verbose = true, |
| 29 |
) { |
| 30 |
} |
| 31 |
|
| 32 |
public function toString(): string |
| 33 |
{ |
| 34 |
return 'format is '.($this->format ?? 'null'); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
protected function matches($response): bool |
| 41 |
{ |
| 42 |
return $this->format === $this->request->getFormat($response->headers->get('Content-Type')); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
protected function failureDescription($response): string |
| 49 |
{ |
| 50 |
return 'the Response '.$this->toString(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
protected function additionalFailureDescription($response): string |
| 57 |
{ |
| 58 |
return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0]; |
| 59 |
} |
| 60 |
} |