Açıklama Yok

EmailTextBodyContains.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 EmailTextBodyContains extends Constraint
  15. {
  16. private $expectedText;
  17. public function __construct(string $expectedText)
  18. {
  19. $this->expectedText = $expectedText;
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function toString(): string
  25. {
  26. return sprintf('contains "%s"', $this->expectedText);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. *
  31. * @param RawMessage $message
  32. */
  33. protected function matches($message): bool
  34. {
  35. if (RawMessage::class === \get_class($message) || Message::class === \get_class($message)) {
  36. throw new \LogicException('Unable to test a message text body on a RawMessage or Message instance.');
  37. }
  38. return false !== mb_strpos($message->getTextBody(), $this->expectedText);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. *
  43. * @param RawMessage $message
  44. */
  45. protected function failureDescription($message): string
  46. {
  47. return 'the Email text body '.$this->toString();
  48. }
  49. }