ResponseStatusCodeSame.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\HttpFoundation\Test\Constraint;
  11. use PHPUnit\Framework\Constraint\Constraint;
  12. use Symfony\Component\HttpFoundation\Response;
  13. final class ResponseStatusCodeSame extends Constraint
  14. {
  15. public function __construct(
  16. private int $statusCode,
  17. private readonly bool $verbose = true,
  18. ) {
  19. }
  20. public function toString(): string
  21. {
  22. return 'status code is '.$this->statusCode;
  23. }
  24. /**
  25. * @param Response $response
  26. */
  27. protected function matches($response): bool
  28. {
  29. return $this->statusCode === $response->getStatusCode();
  30. }
  31. /**
  32. * @param Response $response
  33. */
  34. protected function failureDescription($response): string
  35. {
  36. return 'the Response '.$this->toString();
  37. }
  38. /**
  39. * @param Response $response
  40. */
  41. protected function additionalFailureDescription($response): string
  42. {
  43. return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0];
  44. }
  45. }