ResponseHasHeader.php 1.0 KB

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