mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 08:40:33 +02:00
Throw exception if font file is not found
This commit is contained in:
@@ -72,10 +72,15 @@ class Font implements FontInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
|
* @throws FontException
|
||||||
* @see FontInterface::setFilename()
|
* @see FontInterface::setFilename()
|
||||||
*/
|
*/
|
||||||
public function setFilename(string $filename): FontInterface
|
public function setFilename(string $filename): FontInterface
|
||||||
{
|
{
|
||||||
|
if (!file_exists($filename)) {
|
||||||
|
throw new FontException('Font file ' . $filename . ' does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -13,17 +13,17 @@ final class FontFactoryTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
public function testBuildWithFont(): void
|
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();
|
$result = $factory();
|
||||||
$this->assertInstanceOf(FontInterface::class, $result);
|
$this->assertInstanceOf(FontInterface::class, $result);
|
||||||
$this->assertEquals('foo.ttf', $result->filename());
|
$this->assertEquals($font_file, $result->filename());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBuildWithCallback(): void
|
public function testBuildWithCallback(): void
|
||||||
{
|
{
|
||||||
$factory = new FontFactory(function (FontFactory $font) {
|
$factory = new FontFactory(function (FontFactory $font) {
|
||||||
$font->filename('foo.ttf');
|
$font->filename($this->getTestResourcePath('test.ttf'));
|
||||||
$font->file('bar.ttf');
|
|
||||||
$font->color('#b01735');
|
$font->color('#b01735');
|
||||||
$font->size(70);
|
$font->size(70);
|
||||||
$font->align('center');
|
$font->align('center');
|
||||||
@@ -36,7 +36,7 @@ final class FontFactoryTest extends BaseTestCase
|
|||||||
|
|
||||||
$result = $factory();
|
$result = $factory();
|
||||||
$this->assertInstanceOf(FontInterface::class, $result);
|
$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('#b01735', $result->color());
|
||||||
$this->assertEquals(70, $result->size());
|
$this->assertEquals(70, $result->size());
|
||||||
$this->assertEquals('center', $result->alignment());
|
$this->assertEquals('center', $result->alignment());
|
||||||
|
Reference in New Issue
Block a user