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.

60 lines
1.5 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\Message;
  13. use Symfony\Component\Mime\RawMessage;
  14. final class EmailAttachmentCount extends Constraint
  15. {
  16. private $expectedValue;
  17. private $transport;
  18. public function __construct(int $expectedValue, string $transport = null)
  19. {
  20. $this->expectedValue = $expectedValue;
  21. $this->transport = $transport;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function toString(): string
  27. {
  28. return sprintf('has sent "%d" attachment(s)', $this->expectedValue);
  29. }
  30. /**
  31. * @param RawMessage $message
  32. *
  33. * {@inheritdoc}
  34. */
  35. protected function matches($message): bool
  36. {
  37. if (RawMessage::class === \get_class($message) || Message::class === \get_class($message)) {
  38. throw new \LogicException('Unable to test a message attachment on a RawMessage or Message instance.');
  39. }
  40. return $this->expectedValue === \count($message->getAttachments());
  41. }
  42. /**
  43. * @param RawMessage $message
  44. *
  45. * {@inheritdoc}
  46. */
  47. protected function failureDescription($message): string
  48. {
  49. return 'the Email '.$this->toString();
  50. }
  51. }