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
123123 public function getBody (): string
124124 {
125125 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 ;
127131 }
128132
129133 if (null === $ this ->seekable ) {
Original file line number Diff line number Diff line change @@ -55,6 +55,16 @@ public function testConstructorWithFile()
5555 $ this ->assertSame ('content ' , implode ('' , iterator_to_array ($ p ->bodyToIterable ())));
5656 }
5757
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+
5868 public function testConstructorWithNonStringOrResource ()
5969 {
6070 $ this ->expectException (\TypeError::class);
You can’t perform that action at this time.
0 commit comments