File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
src/Symfony/Component/Mime Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,11 @@ public function getName(): ?string
123
123
public function getBody (): string
124
124
{
125
125
if ($ this ->body instanceof File) {
126
- return file_get_contents ($ this ->body ->getPath ());
126
+ if (false === $ ret = @file_get_contents ($ this ->body ->getPath ())) {
127
+ throw new InvalidArgumentException (error_get_last ()['message ' ]);
128
+ }
129
+
130
+ return $ ret ;
127
131
}
128
132
129
133
if (null === $ this ->seekable ) {
Original file line number Diff line number Diff line change @@ -55,6 +55,16 @@ public function testConstructorWithFile()
55
55
$ this ->assertSame ('content ' , implode ('' , iterator_to_array ($ p ->bodyToIterable ())));
56
56
}
57
57
58
+ public function testConstructorWithUnknownFile ()
59
+ {
60
+ $ p = new TextPart (new File (\dirname (__DIR__ ).'/Fixtures/unknown.txt ' ));
61
+
62
+ // Exception should be thrown only when the body is accessed
63
+ $ this ->expectException (InvalidArgumentException::class);
64
+ $ this ->expectExceptionMessageMatches ('{Failed to open stream} ' );
65
+ $ p ->getBody ();
66
+ }
67
+
58
68
public function testConstructorWithNonStringOrResource ()
59
69
{
60
70
$ this ->expectException (\TypeError::class);
You can’t perform that action at this time.
0 commit comments