From 5dce9f312b85d380e37d815da16f19a8add59954 Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Tue, 2 Aug 2016 16:57:27 +0200 Subject: [PATCH 1/2] Use a dedicated exception in the file locator. --- .../FileLocatorFileNotFoundException.php | 21 +++++++++++++++++++ src/Symfony/Component/Config/FileLocator.php | 6 ++++-- .../Component/Config/FileLocatorInterface.php | 5 ++++- .../Config/Tests/FileLocatorTest.php | 5 +++-- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/Symfony/Component/Config/Exception/FileLocatorFileNotFoundException.php diff --git a/src/Symfony/Component/Config/Exception/FileLocatorFileNotFoundException.php b/src/Symfony/Component/Config/Exception/FileLocatorFileNotFoundException.php new file mode 100644 index 0000000000000..4d4a56dfc66a8 --- /dev/null +++ b/src/Symfony/Component/Config/Exception/FileLocatorFileNotFoundException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Exception; + +/** + * File locator exception if a file does not exist. + * + * @author Leo Feyer + */ +class FileLocatorFileNotFoundException extends \InvalidArgumentException +{ +} diff --git a/src/Symfony/Component/Config/FileLocator.php b/src/Symfony/Component/Config/FileLocator.php index c6600c7783760..8d872e160d0d4 100644 --- a/src/Symfony/Component/Config/FileLocator.php +++ b/src/Symfony/Component/Config/FileLocator.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Config; +use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; + /** * FileLocator uses an array of pre-defined paths to find files. * @@ -41,7 +43,7 @@ public function locate($name, $currentPath = null, $first = true) if ($this->isAbsolutePath($name)) { if (!file_exists($name)) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name)); + throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist.', $name)); } return $name; @@ -66,7 +68,7 @@ public function locate($name, $currentPath = null, $first = true) } if (!$filepaths) { - throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths))); + throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths))); } return $filepaths; diff --git a/src/Symfony/Component/Config/FileLocatorInterface.php b/src/Symfony/Component/Config/FileLocatorInterface.php index 66057982db893..cf3c2e594df85 100644 --- a/src/Symfony/Component/Config/FileLocatorInterface.php +++ b/src/Symfony/Component/Config/FileLocatorInterface.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Config; +use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; + /** * @author Fabien Potencier */ @@ -25,7 +27,8 @@ interface FileLocatorInterface * * @return string|array The full path to the file or an array of file paths * - * @throws \InvalidArgumentException When file is not found + * @throws \InvalidArgumentException If $name is empty + * @throws FileLocatorFileNotFoundException If a file is not found */ public function locate($name, $currentPath = null, $first = true); } diff --git a/src/Symfony/Component/Config/Tests/FileLocatorTest.php b/src/Symfony/Component/Config/Tests/FileLocatorTest.php index d479f2569f1fe..717f068bd7dc6 100644 --- a/src/Symfony/Component/Config/Tests/FileLocatorTest.php +++ b/src/Symfony/Component/Config/Tests/FileLocatorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Config\Tests; +use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; use Symfony\Component\Config\FileLocator; class FileLocatorTest extends \PHPUnit_Framework_TestCase @@ -86,7 +87,7 @@ public function testLocate() } /** - * @expectedException \InvalidArgumentException + * @expectedException FileLocatorFileNotFoundException * @expectedExceptionMessage The file "foobar.xml" does not exist */ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() @@ -97,7 +98,7 @@ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() } /** - * @expectedException \InvalidArgumentException + * @expectedException FileLocatorFileNotFoundException */ public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath() { From 6faf2e6ba722fa7466bfd7e0b8890033b8e6d3ba Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Wed, 3 Aug 2016 09:20:57 +0200 Subject: [PATCH 2/2] Use the FQCN in the @expectedException annotation. --- src/Symfony/Component/Config/Tests/FileLocatorTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Config/Tests/FileLocatorTest.php b/src/Symfony/Component/Config/Tests/FileLocatorTest.php index 717f068bd7dc6..0a03adf125171 100644 --- a/src/Symfony/Component/Config/Tests/FileLocatorTest.php +++ b/src/Symfony/Component/Config/Tests/FileLocatorTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Config\Tests; -use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; use Symfony\Component\Config\FileLocator; class FileLocatorTest extends \PHPUnit_Framework_TestCase @@ -87,7 +86,7 @@ public function testLocate() } /** - * @expectedException FileLocatorFileNotFoundException + * @expectedException \Symfony\Component\Config\Exception\FileLocatorFileNotFoundException * @expectedExceptionMessage The file "foobar.xml" does not exist */ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() @@ -98,7 +97,7 @@ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() } /** - * @expectedException FileLocatorFileNotFoundException + * @expectedException \Symfony\Component\Config\Exception\FileLocatorFileNotFoundException */ public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath() {