Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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\Header\UnstructuredHeader;
16
use Symfony\Component\Mime\RawMessage;
17
 
18
final class EmailHeaderSame extends Constraint
19
{
20
    private string $headerName;
21
    private string $expectedValue;
22
 
23
    public function __construct(string $headerName, string $expectedValue)
24
    {
25
        $this->headerName = $headerName;
26
        $this->expectedValue = $expectedValue;
27
    }
28
 
29
    public function toString(): string
30
    {
31
        return sprintf('has header "%s" with value "%s"', $this->headerName, $this->expectedValue);
32
    }
33
 
34
    /**
35
     * @param RawMessage $message
36
     */
37
    protected function matches($message): bool
38
    {
39
        if (RawMessage::class === $message::class) {
40
            throw new \LogicException('Unable to test a message header on a RawMessage instance.');
41
        }
42
 
43
        return $this->expectedValue === $this->getHeaderValue($message);
44
    }
45
 
46
    /**
47
     * @param RawMessage $message
48
     */
49
    protected function failureDescription($message): string
50
    {
51
        return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message) ?? 'null');
52
    }
53
 
54
    private function getHeaderValue($message): ?string
55
    {
56
        if (null === $header = $message->getHeaders()->get($this->headerName)) {
57
            return null;
58
        }
59
 
60
        return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString();
61
    }
62
}