diff --git a/src/Symfony/Component/Mime/RawMessage.php b/src/Symfony/Component/Mime/RawMessage.php index de3fff38f635d..aed822beaa7e4 100644 --- a/src/Symfony/Component/Mime/RawMessage.php +++ b/src/Symfony/Component/Mime/RawMessage.php @@ -30,11 +30,13 @@ public function toString(): string if (\is_string($this->message)) { return $this->message; } - if ($this->message instanceof \Traversable) { - $this->message = iterator_to_array($this->message, false); + + $message = ''; + foreach ($this->message as $chunk) { + $message .= $chunk; } - return $this->message = implode('', $this->message); + return $this->message = $message; } public function toIterable(): iterable @@ -45,12 +47,9 @@ public function toIterable(): iterable return; } - $message = ''; foreach ($this->message as $chunk) { - $message .= $chunk; yield $chunk; } - $this->message = $message; } /** diff --git a/src/Symfony/Component/Mime/Tests/RawMessageTest.php b/src/Symfony/Component/Mime/Tests/RawMessageTest.php index 264e465dea666..6d53ade9ed496 100644 --- a/src/Symfony/Component/Mime/Tests/RawMessageTest.php +++ b/src/Symfony/Component/Mime/Tests/RawMessageTest.php @@ -19,36 +19,40 @@ class RawMessageTest extends TestCase /** * @dataProvider provideMessages */ - public function testToString($messageParameter) + 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()))); - // calling methods more than once work - $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()))); + } } - public static function provideMessages(): array + /** + * @dataProvider provideMessages + */ + public function testSerialization(mixed $messageParameter, bool $supportReuse) { - return [ - 'string' => ['some string'], - 'traversable' => [new \ArrayObject(['some', ' ', 'string'])], - 'array' => [['some', ' ', 'string']], - ]; + $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()); + } } - public function testSerialization() + public static function provideMessages(): array { - $message = new RawMessage('string'); - $this->assertEquals('string', unserialize(serialize($message))->toString()); - // calling methods more than once work - $this->assertEquals('string', unserialize(serialize($message))->toString()); - - $message = new RawMessage(new \ArrayObject(['some', ' ', 'string'])); - $message = new RawMessage($message->toIterable()); - $this->assertEquals('some string', unserialize(serialize($message))->toString()); - // calling methods more than once work - $this->assertEquals('some string', unserialize(serialize($message))->toString()); + return [ + 'string' => ['some string', true], + 'traversable' => [new \ArrayObject(['some', ' ', 'string']), true], + 'array' => [['some', ' ', 'string'], true], + 'generator' => [(function () { yield 'some'; yield ' '; yield 'string'; })(), false], + ]; } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy