Skip to content

Commit 604ca16

Browse files
Merge branch '6.4' into 7.0
* 6.4: (47 commits) Sync .github/expected-missing-return-types.diff [FrameworkBundle] Add void return-type to ErrorLoggerCompilerPass [DoctrineBridge] Fix cross-versions compat [HttpKernel] Handle nullable callback of StreamedResponse [Mailer] Capitalize sender header for Mailgun [FrameworkBundle] Configure `logger` as error logger if the Monolog Bundle is not registered DX: PHP CS Fixer - drop explicit nullable_type_declaration_for_default_null_value config, as it's part of ruleset anyway DX: PHP CS Fixer - drop explicit no_superfluous_phpdoc_tags config, as it's part of ruleset already [DI] Simplify using DI attributes with `ServiceLocator/Iterator`'s [FrameworkBundle] Fix registering workflow.registry Revert "Add keyword `dev` to leverage composer hint" [Validator] Add missing Ukrainian translations #51960 [Validator] Add missing translations for Indonesian (id) [Validator] Add missing translations for Vietnamese (VI) Add missing Validator translations - Croatian (hr) [HttpFoundation]  Improve PHPDoc of Cache attribute [Validator] Add missing Spanish (es) translations #51956 [Serializer] Add `XmlEncoder::CDATA_WRAPPING` context option [Finder] Add early directory prunning filter support Add missing dutch translations ...
2 parents b33313d + ff0015e commit 604ca16

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

RawMessage.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ public function toString(): string
3030
if (\is_string($this->message)) {
3131
return $this->message;
3232
}
33-
if ($this->message instanceof \Traversable) {
34-
$this->message = iterator_to_array($this->message, false);
33+
34+
$message = '';
35+
foreach ($this->message as $chunk) {
36+
$message .= $chunk;
3537
}
3638

37-
return $this->message = implode('', $this->message);
39+
return $this->message = $message;
3840
}
3941

4042
public function toIterable(): iterable
@@ -45,12 +47,9 @@ public function toIterable(): iterable
4547
return;
4648
}
4749

48-
$message = '';
4950
foreach ($this->message as $chunk) {
50-
$message .= $chunk;
5151
yield $chunk;
5252
}
53-
$this->message = $message;
5453
}
5554

5655
/**

Tests/RawMessageTest.php

+25-21
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,40 @@ class RawMessageTest extends TestCase
1919
/**
2020
* @dataProvider provideMessages
2121
*/
22-
public function testToString($messageParameter)
22+
public function testToString(mixed $messageParameter, bool $supportReuse)
2323
{
2424
$message = new RawMessage($messageParameter);
2525
$this->assertEquals('some string', $message->toString());
2626
$this->assertEquals('some string', implode('', iterator_to_array($message->toIterable())));
27-
// calling methods more than once work
28-
$this->assertEquals('some string', $message->toString());
29-
$this->assertEquals('some string', implode('', iterator_to_array($message->toIterable())));
27+
28+
if ($supportReuse) {
29+
// calling methods more than once work
30+
$this->assertEquals('some string', $message->toString());
31+
$this->assertEquals('some string', implode('', iterator_to_array($message->toIterable())));
32+
}
3033
}
3134

32-
public static function provideMessages(): array
35+
/**
36+
* @dataProvider provideMessages
37+
*/
38+
public function testSerialization(mixed $messageParameter, bool $supportReuse)
3339
{
34-
return [
35-
'string' => ['some string'],
36-
'traversable' => [new \ArrayObject(['some', ' ', 'string'])],
37-
'array' => [['some', ' ', 'string']],
38-
];
40+
$message = new RawMessage($messageParameter);
41+
$this->assertEquals('some string', unserialize(serialize($message))->toString());
42+
43+
if ($supportReuse) {
44+
// calling methods more than once work
45+
$this->assertEquals('some string', unserialize(serialize($message))->toString());
46+
}
3947
}
4048

41-
public function testSerialization()
49+
public static function provideMessages(): array
4250
{
43-
$message = new RawMessage('string');
44-
$this->assertEquals('string', unserialize(serialize($message))->toString());
45-
// calling methods more than once work
46-
$this->assertEquals('string', unserialize(serialize($message))->toString());
47-
48-
$message = new RawMessage(new \ArrayObject(['some', ' ', 'string']));
49-
$message = new RawMessage($message->toIterable());
50-
$this->assertEquals('some string', unserialize(serialize($message))->toString());
51-
// calling methods more than once work
52-
$this->assertEquals('some string', unserialize(serialize($message))->toString());
51+
return [
52+
'string' => ['some string', true],
53+
'traversable' => [new \ArrayObject(['some', ' ', 'string']), true],
54+
'array' => [['some', ' ', 'string'], true],
55+
'generator' => [(function () { yield 'some'; yield ' '; yield 'string'; })(), false],
56+
];
5357
}
5458
}

0 commit comments

Comments
 (0)