Open Journal Systems  3.3.0
EmailTextBodyContains.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 use PHPUnit\Framework\Constraint\Constraint;
17 
18 final class EmailTextBodyContains extends Constraint
19 {
20  private $expectedText;
21 
22  public function __construct(string $expectedText)
23  {
24  $this->expectedText = $expectedText;
25  }
26 
30  public function toString(): string
31  {
32  return sprintf('contains "%s"', $this->expectedText);
33  }
34 
40  protected function matches($message): bool
41  {
42  if (RawMessage::class === \get_class($message) || Message::class === \get_class($message)) {
43  throw new \LogicException('Unable to test a message text body on a RawMessage or Message instance.');
44  }
45 
46  return false !== mb_strpos($message->getTextBody(), $this->expectedText);
47  }
48 
54  protected function failureDescription($message): string
55  {
56  return 'the Email text body '.$this->toString();
57  }
58 }
Symfony\Component\Mime\Test\Constraint
Definition: EmailAddressContains.php:12
Symfony\Component\Mime\Message
Definition: Message.php:22
Symfony\Component\Mime\RawMessage
Definition: RawMessage.php:19
Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains\toString
toString()
Definition: EmailTextBodyContains.php:30
Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains\matches
matches($message)
Definition: EmailTextBodyContains.php:40
Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains
Definition: EmailTextBodyContains.php:18
Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains\__construct
__construct(string $expectedText)
Definition: EmailTextBodyContains.php:22
Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains\failureDescription
failureDescription($message)
Definition: EmailTextBodyContains.php:54