Skip to content

Commit 4105233

Browse files
committed
Merge pull request #75 from jdecool/fix-exceptions
Fix exception code when file not found
2 parents 92c8c6e + 1ba0115 commit 4105233

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/PHPImageWorkshop/ImageWorkshop.php

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class ImageWorkshop
5555
*/
5656
public static function initFromPath($path, $fixOrientation = false)
5757
{
58+
if (!file_exists($path)) {
59+
throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND);
60+
}
61+
5862
if (false === ($imageSizeInfos = @getImageSize($path))) {
5963
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);
6064
}

tests/ImageWorkshopTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testInitFromPath()
4747

4848
// test 3
4949

50-
$this->setExpectedException('PHPImageWorkshop\Exception\ImageWorkshopException');
50+
$this->setExpectedException('PHPImageWorkshop\Exception\ImageWorkshopException', '', ImageWorkshop::ERROR_IMAGE_NOT_FOUND);
5151
$layer = ImageWorkshop::initFromPath('fakePath');
5252
}
5353

0 commit comments

Comments
 (0)