| 148 |
lars |
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 |
|
|
|
12 |
namespace Symfony\Component\Mime\Test\Constraint;
|
|
|
13 |
|
|
|
14 |
use PHPUnit\Framework\Constraint\Constraint;
|
|
|
15 |
use Symfony\Component\Mime\Message;
|
|
|
16 |
use Symfony\Component\Mime\RawMessage;
|
|
|
17 |
|
|
|
18 |
final class EmailHtmlBodyContains extends Constraint
|
|
|
19 |
{
|
|
|
20 |
private string $expectedText;
|
|
|
21 |
|
|
|
22 |
public function __construct(string $expectedText)
|
|
|
23 |
{
|
|
|
24 |
$this->expectedText = $expectedText;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function toString(): string
|
|
|
28 |
{
|
|
|
29 |
return sprintf('contains "%s"', $this->expectedText);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* @param RawMessage $message
|
|
|
34 |
*/
|
|
|
35 |
protected function matches($message): bool
|
|
|
36 |
{
|
|
|
37 |
if (RawMessage::class === $message::class || Message::class === $message::class) {
|
|
|
38 |
throw new \LogicException('Unable to test a message HTML body on a RawMessage or Message instance.');
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return str_contains($message->getHtmlBody(), $this->expectedText);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* @param RawMessage $message
|
|
|
46 |
*/
|
|
|
47 |
protected function failureDescription($message): string
|
|
|
48 |
{
|
|
|
49 |
return 'the Email HTML body '.$this->toString();
|
|
|
50 |
}
|
|
|
51 |
}
|