From 3791a574a242704ecec2ea7a11da74d264bbb86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Tue, 7 Jan 2020 09:14:35 +0100 Subject: [PATCH 1/2] Provide partial packages names if available, closes #8516, fixes #8526 --- .../Repository/ComposerRepository.php | 5 ++++ .../Repository/ComposerRepositoryTest.php | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index c595b20c2..a58896eeb 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -249,6 +249,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $this->loadProviderListings($this->loadRootServerFile()); } + if ($this->hasPartialPackages && null === $this->partialPackagesByName) { + $this->initializePartialPackages(); + return array_keys($this->partialPackagesByName); + } + if ($this->lazyProvidersUrl) { // Can not determine list of provided packages for lazy repositories return array(); diff --git a/tests/Composer/Test/Repository/ComposerRepositoryTest.php b/tests/Composer/Test/Repository/ComposerRepositoryTest.php index 8e9216b35..4ec826334 100644 --- a/tests/Composer/Test/Repository/ComposerRepositoryTest.php +++ b/tests/Composer/Test/Repository/ComposerRepositoryTest.php @@ -271,4 +271,33 @@ class ComposerRepositoryTest extends TestCase ), ); } + + public function testGetProviderNamesWillReturnPartialPackageNames() + { + $rfs = $this->getMockBuilder('Composer\Util\RemoteFilesystem') + ->disableOriginalConstructor() + ->getMock(); + + $rfs->expects($this->at(0)) + ->method('getContents') + ->with('example.org', 'http://example.org/packages.json', false) + ->willReturn(json_encode(array( + 'providers-lazy-url' => '/foo/p/%package%.json', + 'packages' => array('foo/bar' => array( + 'dev-branch' => array(), + 'v1.0.0' => array(), + )) + ))); + + $repository = new ComposerRepository( + array('url' => 'http://example.org/packages.json'), + new NullIO(), + FactoryMock::createConfig(), + null, + $rfs + ); + + $this->assertTrue($repository->hasProviders()); + $this->assertEquals(array('foo/bar'), $repository->getProviderNames()); + } } From 0b767e0b83efa80005a781a8141c94016365f907 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 14 Jan 2020 09:31:27 +0100 Subject: [PATCH 2/2] Allow calling getProviderNames multiple times, refs #8516 --- src/Composer/Repository/ComposerRepository.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index a58896eeb..649c2f115 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -249,8 +249,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $this->loadProviderListings($this->loadRootServerFile()); } - if ($this->hasPartialPackages && null === $this->partialPackagesByName) { - $this->initializePartialPackages(); + if ($this->hasPartialPackages) { + if (null === $this->partialPackagesByName) { + $this->initializePartialPackages(); + } + return array_keys($this->partialPackagesByName); }