14 use PHPUnit\Framework\Constraint\Constraint;
22 private $expectedValue;
24 public function __construct(
string $headerName,
string $expectedValue)
26 $this->headerName = $headerName;
27 $this->expectedValue = $expectedValue;
35 return sprintf(
'contains address "%s" with value "%s"', $this->headerName, $this->expectedValue);
43 protected function matches($message): bool
45 if (RawMessage::class === \get_class($message)) {
46 throw new \LogicException(
'Unable to test a message address on a RawMessage instance.');
49 $header = $message->getHeaders()->get($this->headerName);
51 return $this->expectedValue === $header->getAddress()->getAddress();
53 foreach ($header->getAddresses() as $address) {
54 if ($this->expectedValue === $address->getAddress()) {
62 throw new \LogicException(sprintf(
'Unable to test a message address on a non-address header.'));
72 return sprintf(
'the Email %s (value is %s)', $this->
toString(), $message->getHeaders()->get($this->headerName)->getBodyAsString());