ResponseHeaderSame.php 1.2 KB

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