RequestAttributeValueSame.php 1.0 KB

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