From 1ba0115b4d60186274f75f317a1730de3dea1645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Mon, 1 Jun 2015 07:40:25 +0200 Subject: [PATCH] Fix exception code when file not found --- src/PHPImageWorkshop/ImageWorkshop.php | 4 ++++ tests/ImageWorkshopTest.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PHPImageWorkshop/ImageWorkshop.php b/src/PHPImageWorkshop/ImageWorkshop.php index 914edd0..6944bdd 100644 --- a/src/PHPImageWorkshop/ImageWorkshop.php +++ b/src/PHPImageWorkshop/ImageWorkshop.php @@ -55,6 +55,10 @@ class ImageWorkshop */ public static function initFromPath($path, $fixOrientation = false) { + if (!file_exists($path)) { + throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND); + } + if (false === ($imageSizeInfos = @getImageSize($path))) { throw new ImageWorkshopException('Can\'t open the file at "'.$path.'" : file is not readable, did you check permissions (755 / 777) ?', static::ERROR_NOT_READABLE_FILE); } diff --git a/tests/ImageWorkshopTest.php b/tests/ImageWorkshopTest.php index dc5fab8..4f23dc9 100644 --- a/tests/ImageWorkshopTest.php +++ b/tests/ImageWorkshopTest.php @@ -47,7 +47,7 @@ public function testInitFromPath() // test 3 - $this->setExpectedException('PHPImageWorkshop\Exception\ImageWorkshopException'); + $this->setExpectedException('PHPImageWorkshop\Exception\ImageWorkshopException', '', ImageWorkshop::ERROR_IMAGE_NOT_FOUND); $layer = ImageWorkshop::initFromPath('fakePath'); }