Ver Fonte

Merge pull request #8363 from sincilite/feature/error-reporting-for-missing-path

Improve error reporting for missing path in Repository Path
Jordi Boggiano há 5 anos atrás
pai
commit
18dad48fa6

+ 7 - 1
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';
 

+ 16 - 0
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')