Skip to content

Commit 3fe8926

Browse files
[Mime] Fix RawMessage constructor argument type
1 parent 7d04896 commit 3fe8926

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

RawMessage.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
*/
1919
class RawMessage
2020
{
21-
/** @var iterable|string|resource */
21+
/** @var iterable<string>|string|resource */
2222
private $message;
2323
private bool $isGeneratorClosed;
2424

25-
public function __construct(iterable|string $message)
25+
/**
26+
* @param iterable<string>|string|resource $message
27+
*/
28+
public function __construct(mixed $message)
2629
{
2730
$this->message = $message;
2831
}

Tests/RawMessageTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ public function testToIterableLegacy(mixed $messageParameter, bool $supportReuse
8080
}
8181
}
8282

83+
public function testToIterableOnResourceRewindsAndYieldsLines()
84+
{
85+
$handle = \fopen('php://memory', 'r+');
86+
\fwrite($handle, "line1\nline2\nline3\n");
87+
88+
$message = new RawMessage($handle);
89+
$this->assertSame("line1\nline2\nline3\n", implode('', iterator_to_array($message->toIterable())));
90+
}
91+
92+
public function testDestructClosesResource()
93+
{
94+
$handle = fopen('php://memory', 'r+');
95+
96+
$message = new RawMessage($handle);
97+
unset($message);
98+
99+
$this->assertIsClosedResource($handle);
100+
}
101+
83102
public static function provideMessages(): array
84103
{
85104
return [

0 commit comments

Comments
 (0)