Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mime] Allow array as input for RawMessage #42976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Mime/RawMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ 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);
}

return $this->message = implode('', iterator_to_array($this->message, false));
return $this->message = implode('', $this->message);
}

public function toIterable(): iterable
Expand Down
23 changes: 14 additions & 9 deletions src/Symfony/Component/Mime/Tests/RawMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@

class RawMessageTest extends TestCase
{
public function testToString()
/**
* @dataProvider provideMessages
*/
public function testToString($messageParameter)
{
$message = new RawMessage('string');
$this->assertEquals('string', $message->toString());
$this->assertEquals('string', implode('', iterator_to_array($message->toIterable())));
// calling methods more than once work
$this->assertEquals('string', $message->toString());
$this->assertEquals('string', implode('', iterator_to_array($message->toIterable())));

$message = new RawMessage(new \ArrayObject(['some', ' ', 'string']));
$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())));
}

public function provideMessages(): array
{
return [
'string' => ['some string'],
'traversable' => [new \ArrayObject(['some', ' ', 'string'])],
'array' => [['some', ' ', 'string']],
];
}

public function testSerialization()
{
$message = new RawMessage('string');
Expand Down