File tree 2 files changed +16
-1
lines changed
2 files changed +16
-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 12
12
namespace Symfony \Component \Mime \Tests \Part ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Mime \Exception \InvalidArgumentException ;
15
16
use Symfony \Component \Mime \Header \Headers ;
16
17
use Symfony \Component \Mime \Header \ParameterizedHeader ;
17
18
use Symfony \Component \Mime \Header \UnstructuredHeader ;
@@ -55,6 +56,16 @@ public function testConstructorWithFile()
55
56
$ this ->assertSame ('content ' , implode ('' , iterator_to_array ($ p ->bodyToIterable ())));
56
57
}
57
58
59
+ public function testConstructorWithUnknownFile ()
60
+ {
61
+ $ p = new TextPart (new File (\dirname (__DIR__ ).'/Fixtures/unknown.txt ' ));
62
+
63
+ // Exception should be thrown only when the body is accessed
64
+ $ this ->expectException (InvalidArgumentException::class);
65
+ $ this ->expectExceptionMessageMatches ('{Failed to open stream} ' );
66
+ $ p ->getBody ();
67
+ }
68
+
58
69
public function testConstructorWithNonStringOrResource ()
59
70
{
60
71
$ this ->expectException (\TypeError::class);
You can’t perform that action at this time.
0 commit comments