1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Throw exception if font file is not found

This commit is contained in:
Oliver Vogel
2024-06-11 16:15:55 +02:00
parent 27512eedb3
commit 13c166d104
2 changed files with 10 additions and 5 deletions

View File

@@ -72,10 +72,15 @@ class Font implements FontInterface
/**
* {@inheritdoc}
*
* @throws FontException
* @see FontInterface::setFilename()
*/
public function setFilename(string $filename): FontInterface
{
if (!file_exists($filename)) {
throw new FontException('Font file ' . $filename . ' does not exist.');
}
$this->filename = $filename;
return $this;

View File

@@ -13,17 +13,17 @@ final class FontFactoryTest extends BaseTestCase
{
public function testBuildWithFont(): void
{
$factory = new FontFactory(new Font('foo.ttf'));
$font_file = $this->getTestResourcePath('test.ttf');
$factory = new FontFactory(new Font($font_file));
$result = $factory();
$this->assertInstanceOf(FontInterface::class, $result);
$this->assertEquals('foo.ttf', $result->filename());
$this->assertEquals($font_file, $result->filename());
}
public function testBuildWithCallback(): void
{
$factory = new FontFactory(function (FontFactory $font) {
$font->filename('foo.ttf');
$font->file('bar.ttf');
$font->filename($this->getTestResourcePath('test.ttf'));
$font->color('#b01735');
$font->size(70);
$font->align('center');
@@ -36,7 +36,7 @@ final class FontFactoryTest extends BaseTestCase
$result = $factory();
$this->assertInstanceOf(FontInterface::class, $result);
$this->assertEquals('bar.ttf', $result->filename());
$this->assertEquals($this->getTestResourcePath('test.ttf'), $result->filename());
$this->assertEquals('#b01735', $result->color());
$this->assertEquals(70, $result->size());
$this->assertEquals('center', $result->alignment());