You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

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