EmailHasHeader.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. public function __construct(
  16. private string $headerName,
  17. ) {
  18. }
  19. public function toString(): string
  20. {
  21. return sprintf('has header "%s"', $this->headerName);
  22. }
  23. /**
  24. * @param RawMessage $message
  25. */
  26. protected function matches($message): bool
  27. {
  28. if (RawMessage::class === $message::class) {
  29. throw new \LogicException('Unable to test a message header on a RawMessage instance.');
  30. }
  31. return $message->getHeaders()->has($this->headerName);
  32. }
  33. /**
  34. * @param RawMessage $message
  35. */
  36. protected function failureDescription($message): string
  37. {
  38. return 'the Email '.$this->toString();
  39. }
  40. }