Skip to content

Commit

Permalink
[Mime] Fix RawMessage constructor argument type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Jul 31, 2024
1 parent 7d04896 commit 3fe8926
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions RawMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
*/
class RawMessage
{
/** @var iterable|string|resource */
/** @var iterable<string>|string|resource */
private $message;
private bool $isGeneratorClosed;

public function __construct(iterable|string $message)
/**
* @param iterable<string>|string|resource $message
*/
public function __construct(mixed $message)
{
$this->message = $message;
}
Expand Down
19 changes: 19 additions & 0 deletions Tests/RawMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ public function testToIterableLegacy(mixed $messageParameter, bool $supportReuse
}
}

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 testDestructClosesResource()
{
$handle = fopen('php://memory', 'r+');

$message = new RawMessage($handle);
unset($message);

$this->assertIsClosedResource($handle);
}

public static function provideMessages(): array
{
return [
Expand Down

0 comments on commit 3fe8926

Please sign in to comment.