Dashboard sipadu mbip
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.

RequestAttributeValueSame.php 1.1KB

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