RequestAttributeValueSame.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Request;
  13. final class RequestAttributeValueSame extends Constraint
  14. {
  15. private $name;
  16. private $value;
  17. public function __construct(string $name, string $value)
  18. {
  19. $this->name = $name;
  20. $this->value = $value;
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function toString(): string
  26. {
  27. return sprintf('has attribute "%s" with value "%s"', $this->name, $this->value);
  28. }
  29. /**
  30. * @param Request $request
  31. *
  32. * {@inheritdoc}
  33. */
  34. protected function matches($request): bool
  35. {
  36. return $this->value === $request->attributes->get($this->name);
  37. }
  38. /**
  39. * @param Request $request
  40. *
  41. * {@inheritdoc}
  42. */
  43. protected function failureDescription($request): string
  44. {
  45. return 'the Request '.$this->toString();
  46. }
  47. }