From 94eebdf3d9d810cc98a4fd0b4c98ef553abd91a8 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Thu, 9 Feb 2017 22:42:51 -0500 Subject: [PATCH] locator should throw liip namespaced exceptions --- Binary/Locator/FileSystemLocator.php | 14 ++++++++++---- .../Locator/AbstractFileSystemLocatorTest.php | 11 +++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Binary/Locator/FileSystemLocator.php b/Binary/Locator/FileSystemLocator.php index 7a105edbc..1cff51d92 100644 --- a/Binary/Locator/FileSystemLocator.php +++ b/Binary/Locator/FileSystemLocator.php @@ -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 @@ -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']); } @@ -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; diff --git a/Tests/Binary/Locator/AbstractFileSystemLocatorTest.php b/Tests/Binary/Locator/AbstractFileSystemLocatorTest.php index abab2ba4b..7db1dae26 100644 --- a/Tests/Binary/Locator/AbstractFileSystemLocatorTest.php +++ b/Tests/Binary/Locator/AbstractFileSystemLocatorTest.php @@ -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')); + } }