diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index 6e218f159..2f26af2f7 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -125,7 +125,13 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn { parent::initialize(); - foreach ($this->getUrlMatches() as $url) { + $urlMatches = $this->getUrlMatches(); + + if (empty($urlMatches)) { + throw new \RuntimeException('The `url` supplied for the path (' . $this->url . ') repository does not exist'); + } + + foreach ($urlMatches as $url) { $path = realpath($url) . DIRECTORY_SEPARATOR; $composerFilePath = $path.'composer.json'; diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index a9594257c..159d8cc97 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -19,6 +19,22 @@ use Composer\Test\TestCase; class PathRepositoryTest extends TestCase { + + /** + * @expectedException RuntimeException + */ + public function testLoadPackageFromFileSystemWithIncorrectPath() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + + $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'missing')); + $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config); + $repository->getPackages(); + } + public function testLoadPackageFromFileSystemWithVersion() { $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')