From 18895064ad12bbe165221029f166eff368e4e833 Mon Sep 17 00:00:00 2001 From: Mike van Rooyen Date: Tue, 8 Oct 2019 15:46:35 +0100 Subject: [PATCH 1/5] Check that if the getUrlMatches method returns an empty value which means the path is incorrect --- src/Composer/Repository/PathRepository.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index 6e218f159..d5d21b609 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 repository does not exist'); + } + + foreach ($urlMatches as $url) { $path = realpath($url) . DIRECTORY_SEPARATOR; $composerFilePath = $path.'composer.json'; From e62478ab896115d5014e0f5eba6e571c723b789e Mon Sep 17 00:00:00 2001 From: Mike van Rooyen Date: Tue, 8 Oct 2019 15:48:04 +0100 Subject: [PATCH 2/5] Test to check there is a RuntimeException thrown when a path repository doesn't exist --- .../Test/Repository/PathRepositoryTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index a9594257c..fde704066 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -19,6 +19,24 @@ use Composer\Test\TestCase; class PathRepositoryTest extends TestCase { + + /** + * @expectedException RuntimeException + */ + public function testLoadPackageFromFileSystemWithIncorrectPath() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + $versionGuesser = null; + + $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') From e910e06f6333d409e5379f7baa3a80e6cf5680b8 Mon Sep 17 00:00:00 2001 From: Mike van Rooyen Date: Tue, 8 Oct 2019 16:02:03 +0100 Subject: [PATCH 3/5] Add details of the path to aid debugging --- src/Composer/Repository/PathRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index d5d21b609..2f26af2f7 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -128,7 +128,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn $urlMatches = $this->getUrlMatches(); if (empty($urlMatches)) { - throw new \RuntimeException('The `url` supplied for the path repository does not exist'); + throw new \RuntimeException('The `url` supplied for the path (' . $this->url . ') repository does not exist'); } foreach ($urlMatches as $url) { From daedb4a74fd253b3b30a8c9e5eab50085f8279f9 Mon Sep 17 00:00:00 2001 From: Mike van Rooyen Date: Tue, 8 Oct 2019 16:08:11 +0100 Subject: [PATCH 4/5] Remove extra line in method following CS-Fixer --- tests/Composer/Test/Repository/PathRepositoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index fde704066..c02c02838 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -34,7 +34,6 @@ class PathRepositoryTest extends TestCase $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'missing')); $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config); $repository->getPackages(); - } public function testLoadPackageFromFileSystemWithVersion() From 6b56ddae2a2c2eedafc378a3bcae0c5cb06ee843 Mon Sep 17 00:00:00 2001 From: Mike van Rooyen Date: Tue, 8 Oct 2019 20:49:44 +0100 Subject: [PATCH 5/5] Remove unused variable --- tests/Composer/Test/Repository/PathRepositoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index c02c02838..159d8cc97 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -29,7 +29,6 @@ class PathRepositoryTest extends TestCase ->getMock(); $config = new \Composer\Config(); - $versionGuesser = null; $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'missing')); $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);