Open Journal Systems  3.3.0
EmailAttachmentCount.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 EmailAttachmentCount extends Constraint
19 {
20  private $expectedValue;
21  private $transport;
22 
23  public function __construct(int $expectedValue, string $transport = null)
24  {
25  $this->expectedValue = $expectedValue;
26  $this->transport = $transport;
27  }
28 
32  public function toString(): string
33  {
34  return sprintf('has sent "%d" attachment(s)', $this->expectedValue);
35  }
36 
42  protected function matches($message): bool
43  {
44  if (RawMessage::class === \get_class($message) || Message::class === \get_class($message)) {
45  throw new \LogicException('Unable to test a message attachment on a RawMessage or Message instance.');
46  }
47 
48  return $this->expectedValue === \count($message->getAttachments());
49  }
50 
56  protected function failureDescription($message): string
57  {
58  return 'the Email '.$this->toString();
59  }
60 }
Symfony\Component\Mime\Test\Constraint
Definition: EmailAddressContains.php:12
Symfony\Component\Mime\Test\Constraint\EmailAttachmentCount
Definition: EmailAttachmentCount.php:18
Symfony\Component\Mime\Message
Definition: Message.php:22
Symfony\Component\Mime\RawMessage
Definition: RawMessage.php:19
Symfony\Component\Mime\Test\Constraint\EmailAttachmentCount\failureDescription
failureDescription($message)
Definition: EmailAttachmentCount.php:56
Symfony\Component\Mime\Test\Constraint\EmailAttachmentCount\toString
toString()
Definition: EmailAttachmentCount.php:32
Symfony\Component\Mime\Test\Constraint\EmailAttachmentCount\__construct
__construct(int $expectedValue, string $transport=null)
Definition: EmailAttachmentCount.php:23
Symfony\Component\Mime\Test\Constraint\EmailAttachmentCount\matches
matches($message)
Definition: EmailAttachmentCount.php:42