Permalink
Browse files

[stream] throws exception when content cannot be read.

  • Loading branch information...
1 parent 006a641 commit b2e579a811db4a941846acc3141edb7974c52683 @makasim makasim committed Jun 5, 2014
Showing with 18 additions and 4 deletions.
  1. +12 −2 Binary/Loader/StreamLoader.php
  2. +6 −2 Tests/Binary/Loader/StreamLoaderTest.php
@@ -52,12 +52,22 @@ public function find($path)
* file_exists() is not used as not all wrappers support stat() to actually check for existing resources.
*/
if (($this->context && !$resource = @fopen($name, 'r', null, $this->context)) || !$resource = @fopen($name, 'r')) {
- throw new NotLoadableException('Source image not found.');
+ throw new NotLoadableException(sprintf('Source image %s not found.', $name));
}
// Closing the opened stream to avoid locking of the resource to find.
fclose($resource);
- return file_get_contents($name, null, $this->context);
+ try {
+ $content = file_get_contents($name, null, $this->context);
+ } catch (\Exception $e) {
+ throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $name, $e));
+ }
+
+ if (false === $content) {
+ throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $name));
+ }
+
+ return $content;
}
}
@@ -14,10 +14,14 @@ public function testThrowsIfInvalidPathGivenOnFind()
{
$loader = new StreamLoader('file://');
+ $path = $this->tempDir.'/invalid.jpeg';
+
$this->setExpectedException(
- 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException'
+ 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException',
+ 'Source image file://'.$path.' not found.'
);
- $loader->find($this->tempDir.'/invalid.jpeg');
+
+ $loader->find($path);
}
public function testReturnImageContentOnFind()

0 comments on commit b2e579a

Please sign in to comment.