Debian Codegraph @

lib/3rdParty/composer/symfony/http-foundation/Test/Constraint/ResponseFormatSame.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
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 * Asserts that the response is in the given format.
20 *
21 * @author Kévin Dunglas <[email protected]>
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 * @param Response $response
39 */
40 protected function matches($response): bool
41 {
42 return $this->format === $this->request->getFormat($response->headers->get('Content-Type'));
43 }
44
45 /**
46 * @param Response $response
47 */
48 protected function failureDescription($response): string
49 {
50 return 'the Response '.$this->toString();
51 }
52
53 /**
54 * @param Response $response
55 */
56 protected function additionalFailureDescription($response): string
57 {
58 return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0];
59 }
60 }