Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [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
  • Loading branch information
fabpot committed Jun 2, 2024
2 parents 22ca1de + 618597a commit 3426d1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Part/TextPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public function getName(): ?string
public function getBody(): string
{
if ($this->body instanceof File) {
return file_get_contents($this->body->getPath());
if (false === $ret = @file_get_contents($this->body->getPath())) {
throw new InvalidArgumentException(error_get_last()['message']);
}

return $ret;
}

if (null === $this->seekable) {
Expand Down
11 changes: 11 additions & 0 deletions Tests/Part/TextPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Mime\Tests\Part;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Header\ParameterizedHeader;
use Symfony\Component\Mime\Header\UnstructuredHeader;
Expand Down Expand Up @@ -55,6 +56,16 @@ public function testConstructorWithFile()
$this->assertSame('content', implode('', iterator_to_array($p->bodyToIterable())));
}

public function testConstructorWithUnknownFile()
{
$p = new TextPart(new File(\dirname(__DIR__).'/Fixtures/unknown.txt'));

// Exception should be thrown only when the body is accessed
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageMatches('{Failed to open stream}');
$p->getBody();
}

public function testConstructorWithNonStringOrResource()
{
$this->expectException(\TypeError::class);
Expand Down

0 comments on commit 3426d1e

Please sign in to comment.