Skip to content

Commit 0c47635

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: [Scheduler] Throw an exception when no dispatcher has been passed to a Schedule [Mime] Fix TextPart using an unknown File Fix autoload configs to avoid warnings when building optimized autoloaders Fix autoload configs to avoid warnings when building optimized autoloaders
2 parents 9a3ff55 + 8ada3ef commit 0c47635

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Part/TextPart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ public function getName(): ?string
125125
public function getBody(): string
126126
{
127127
if ($this->body instanceof File) {
128-
return file_get_contents($this->body->getPath());
128+
if (false === $ret = @file_get_contents($this->body->getPath())) {
129+
throw new InvalidArgumentException(error_get_last()['message']);
130+
}
131+
132+
return $ret;
129133
}
130134

131135
if (null === $this->seekable) {

Tests/Part/TextPartTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public function testConstructorWithFile()
5858
$this->assertSame('content', implode('', iterator_to_array($p->bodyToIterable())));
5959
}
6060

61+
public function testConstructorWithUnknownFile()
62+
{
63+
$p = new TextPart(new File(\dirname(__DIR__).'/Fixtures/unknown.txt'));
64+
65+
// Exception should be thrown only when the body is accessed
66+
$this->expectException(InvalidArgumentException::class);
67+
$this->expectExceptionMessageMatches('{Failed to open stream}');
68+
$p->getBody();
69+
}
70+
6171
public function testConstructorWithNonStringOrResource()
6272
{
6373
$this->expectException(\TypeError::class);

0 commit comments

Comments
 (0)