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