/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Mime/Tests/RawMessageTest.php
112 строк
4 KB
Nicolas Grekas
Merge branch '6.4' into 7.4
11 авг 2026, 16:33
11 авг 2026, 16:33
6ca4142
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Mime\Tests; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Mime\Exception\LogicException; use Symfony\Component\Mime\RawMessage; class RawMessageTest extends TestCase { #[DataProvider('provideMessages')] public function testToString(mixed $messageParameter, bool $supportReuse) { $message = new RawMessage($messageParameter); $this->assertEquals('some string', $message->toString()); $this->assertEquals('some string', implode('', iterator_to_array($message->toIterable()))); if ($supportReuse) { // calling methods more than once work $this->assertEquals('some string', $message->toString()); $this->assertEquals('some string', implode('', iterator_to_array($message->toIterable()))); } } #[DataProvider('provideMessages')] public function testSerialization(mixed $messageParameter, bool $supportReuse) { $message = new RawMessage($messageParameter); $this->assertEquals('some string', unserialize(serialize($message))->toString()); if ($supportReuse) { // calling methods more than once work $this->assertEquals('some string', unserialize(serialize($message))->toString()); } } #[DataProvider('provideMessages')] public function testToIterable(mixed $messageParameter, bool $supportReuse) { $message = new RawMessage($messageParameter); $this->assertEquals('some string', implode('', iterator_to_array($message->toIterable()))); if ($supportReuse) { // calling methods more than once work $this->assertEquals('some string', implode('', iterator_to_array($message->toIterable()))); } } #[DataProvider('provideMessages')] public function testToIterableLegacy(mixed $messageParameter, bool $supportReuse) { $message = new RawMessage($messageParameter); $this->assertEquals('some string', implode('', iterator_to_array($message->toIterable()))); if (!$supportReuse) { $this->expectException(LogicException::class); iterator_to_array($message->toIterable()); } } public function testToIterableOnResourceRewindsAndYieldsLines() { $handle = fopen('php://memory', 'r+'); fwrite($handle, "line1\nline2\nline3\n"); $message = new RawMessage($handle); $this->assertSame("line1\nline2\nline3\n", implode('', iterator_to_array($message->toIterable()))); } public function testToIterableOnResourceYieldsAFinalFalsyLine() { $handle = fopen('php://memory', 'r+'); fwrite($handle, "line1\n0"); $message = new RawMessage($handle); $this->assertSame("line1\n0", implode('', iterator_to_array($message->toIterable()))); } public function testDestructClosesResource() { $handle = fopen('php://memory', 'r+'); $message = new RawMessage($handle); unset($message); $this->assertIsClosedResource($handle); } public static function provideMessages(): array { return [ 'string' => ['some string', true], 'traversable' => [new \ArrayObject(['some', ' ', 'string']), true], 'array' => [['some', ' ', 'string'], true], 'generator' => [(static function () { yield 'some'; yield ' '; yield 'string'; })(), false], ]; } }