ResponseHasHeader.php 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 ResponseHasHeader extends Constraint
  14. {
  15. public function __construct(
  16. private string $headerName,
  17. ) {
  18. }
  19. public function toString(): string
  20. {
  21. return \sprintf('has header "%s"', $this->headerName);
  22. }
  23. /**
  24. * @param Response $response
  25. */
  26. protected function matches($response): bool
  27. {
  28. return $response->headers->has($this->headerName);
  29. }
  30. /**
  31. * @param Response $response
  32. */
  33. protected function failureDescription($response): string
  34. {
  35. return 'the Response '.$this->toString();
  36. }
  37. }