Skip to content

Commit

Permalink
locator should throw liip namespaced exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrawley committed Feb 10, 2017
1 parent 30aea40 commit 94eebdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Binary/Locator/FileSystemLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
use Liip\ImagineBundle\Exception\InvalidArgumentException;
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class FileSystemLocator implements LocatorInterface
Expand All @@ -27,9 +28,14 @@ class FileSystemLocator implements LocatorInterface
*/
public function setOptions(array $options = array())
{
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefaults(array('roots' => array()));
$options = $optionsResolver->resolve($options);
$resolver = new OptionsResolver();
$resolver->setDefaults(array('roots' => array()));

try {
$options = $resolver->resolve($options);
} catch (ExceptionInterface $e) {
throw new InvalidArgumentException(sprintf('Invalid options provided to %s()', __METHOD__), null, $e);
}

$this->roots = array_map(array($this, 'sanitizeRootPath'), (array) $options['roots']);
}
Expand Down Expand Up @@ -71,7 +77,7 @@ protected function generateAbsolutePath($root, $path)
*
* @return string
*/
protected function sanitizeRootPath($root)
private function sanitizeRootPath($root)
{
if (!empty($root) && false !== $realRoot = realpath($root)) {
return $realRoot;
Expand Down
11 changes: 11 additions & 0 deletions Tests/Binary/Locator/AbstractFileSystemLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ public function testMultipleRootLoadCases($rootDirs, $path)
{
$this->assertNotNull($this->getLocator($rootDirs)->locate($path));
}

public function testThrowsExceptionOnInvalidOptions()
{
$this->setExpectedException(
'Liip\ImagineBundle\Exception\InvalidArgumentException',
'Invalid options provided to'
);

$locator = $this->getLocator(__DIR__);
$locator->setOptions(array('foo' => 'bar'));
}
}

0 comments on commit 94eebdf

Please sign in to comment.