No Description

EmailHasHeader.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Mime\Test\Constraint;
  11. use PHPUnit\Framework\Constraint\Constraint;
  12. use Symfony\Component\Mime\RawMessage;
  13. final class EmailHasHeader extends Constraint
  14. {
  15. private $headerName;
  16. public function __construct(string $headerName)
  17. {
  18. $this->headerName = $headerName;
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function toString(): string
  24. {
  25. return sprintf('has header "%s"', $this->headerName);
  26. }
  27. /**
  28. * @param RawMessage $message
  29. *
  30. * {@inheritdoc}
  31. */
  32. protected function matches($message): bool
  33. {
  34. if (RawMessage::class === \get_class($message)) {
  35. throw new \LogicException('Unable to test a message header on a RawMessage instance.');
  36. }
  37. return $message->getHeaders()->has($this->headerName);
  38. }
  39. /**
  40. * @param RawMessage $message
  41. *
  42. * {@inheritdoc}
  43. */
  44. protected function failureDescription($message): string
  45. {
  46. return 'the Email '.$this->toString();
  47. }
  48. }