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.

57 lines
1.2 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\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. }