|
12 | 12 | namespace Symfony\Component\Mime\Tests\Part;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Mime\Encoder\ContentEncoderInterface; |
15 | 16 | use Symfony\Component\Mime\Header\Headers;
|
16 | 17 | use Symfony\Component\Mime\Header\ParameterizedHeader;
|
17 | 18 | use Symfony\Component\Mime\Header\UnstructuredHeader;
|
@@ -87,6 +88,35 @@ public function testEncoding()
|
87 | 88 | ), $p->getPreparedHeaders());
|
88 | 89 | }
|
89 | 90 |
|
| 91 | + public function testCustomEncoding() |
| 92 | + { |
| 93 | + $p = new TextPart('content', 'utf-8', 'plain', 'test_encoding'); |
| 94 | + $p->addEncoder('test_encoding', new class() implements ContentEncoderInterface { |
| 95 | + public function encodeByteStream($stream, int $maxLineLength = 0): iterable |
| 96 | + { |
| 97 | + while (!feof($stream)) { |
| 98 | + yield fread($stream, 16372); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + public function getName(): string |
| 103 | + { |
| 104 | + return 'test_encoding'; |
| 105 | + } |
| 106 | + |
| 107 | + public function encodeString(string $string, ?string $charset = 'utf-8', int $firstLineOffset = 0, int $maxLineLength = 0): string |
| 108 | + { |
| 109 | + return $string; |
| 110 | + } |
| 111 | + }); |
| 112 | + $this->assertEquals('content', $p->bodyToString()); |
| 113 | + $this->assertEquals('content', implode('', iterator_to_array($p->bodyToIterable()))); |
| 114 | + $this->assertEquals(new Headers( |
| 115 | + new ParameterizedHeader('Content-Type', 'text/plain', ['charset' => 'utf-8']), |
| 116 | + new UnstructuredHeader('Content-Transfer-Encoding', 'test_encoding') |
| 117 | + ), $p->getPreparedHeaders()); |
| 118 | + } |
| 119 | + |
90 | 120 | public function testSerialize()
|
91 | 121 | {
|
92 | 122 | $r = fopen('php://memory', 'r+', false);
|
|
0 commit comments