bug #37583 [Mime] Fix EmailHeaderSame to make use of decoded value (evertharmeling)

This PR was merged into the 4.4 branch.

Discussion
----------

[Mime] Fix EmailHeaderSame to make use of decoded value

Fixes #35062

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  |no
| Deprecations? | no
| Tickets       | Fix #35062
| License       | MIT

Commits
-------

8a3f50746d Fix EmailHeaderSame to make use of decoded value
This commit is contained in:
Nicolas Grekas 2020-07-23 11:59:39 +02:00
commit df1a1ff069
1 changed files with 10 additions and 2 deletions

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Header\UnstructuredHeader;
use Symfony\Component\Mime\RawMessage;
final class EmailHeaderSame extends Constraint
@ -44,7 +45,7 @@ final class EmailHeaderSame extends Constraint
throw new \LogicException('Unable to test a message header on a RawMessage instance.');
}
return $this->expectedValue === $message->getHeaders()->get($this->headerName)->getBodyAsString();
return $this->expectedValue === $this->getHeaderValue($message);
}
/**
@ -54,6 +55,13 @@ final class EmailHeaderSame extends Constraint
*/
protected function failureDescription($message): string
{
return sprintf('the Email %s (value is %s)', $this->toString(), $message->getHeaders()->get($this->headerName)->getBodyAsString());
return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message));
}
private function getHeaderValue($message): string
{
$header = $message->getHeaders()->get($this->headerName);
return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString();
}
}