Open Monograph Press  3.3.0
EmailHasHeader.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;
16 
17 final class EmailHasHeader extends Constraint
18 {
19  private $headerName;
20 
21  public function __construct(string $headerName)
22  {
23  $this->headerName = $headerName;
24  }
25 
29  public function toString(): string
30  {
31  return sprintf('has header "%s"', $this->headerName);
32  }
33 
39  protected function matches($message): bool
40  {
41  if (RawMessage::class === \get_class($message)) {
42  throw new \LogicException('Unable to test a message header on a RawMessage instance.');
43  }
44 
45  return $message->getHeaders()->has($this->headerName);
46  }
47 
53  protected function failureDescription($message): string
54  {
55  return 'the Email '.$this->toString();
56  }
57 }
Symfony\Component\Mime\Test\Constraint\EmailHasHeader
Definition: EmailHasHeader.php:17
Symfony\Component\Mime\Test\Constraint
Definition: EmailAddressContains.php:12
Symfony\Component\Mime\Test\Constraint\EmailHasHeader\__construct
__construct(string $headerName)
Definition: EmailHasHeader.php:21
Symfony\Component\Mime\Test\Constraint\EmailHasHeader\failureDescription
failureDescription($message)
Definition: EmailHasHeader.php:53
Symfony\Component\Mime\Test\Constraint\EmailHasHeader\matches
matches($message)
Definition: EmailHasHeader.php:39
Symfony\Component\Mime\Test\Constraint\EmailHasHeader\toString
toString()
Definition: EmailHasHeader.php:29
Symfony\Component\Mime\RawMessage
Definition: RawMessage.php:19