Skip to content

Commit

Permalink
Add support for non-Packagist Composer repos in the back end of the P…
Browse files Browse the repository at this point in the history
…ieJsonEditor

NOTE: that this does not enable support in the repository add command, as
Private Packagist does not yet appear to pass down the `php-ext` metadata,
meaning some packages won't actually work.

See: php#175
  • Loading branch information
asgrim committed Jan 22, 2025
1 parent 2e67ee5 commit bb8a463
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,16 @@ public static function listRepositories(Composer $composer, OutputInterface $out

foreach ($composer->getRepositoryManager()->getRepositories() as $repo) {
if ($repo instanceof ComposerRepository) {
$output->writeln(' - Packagist (cannot be removed)');
$repoConfig = $repo->getRepoConfig();

$repoUrl = array_key_exists('url', $repoConfig) && is_string($repoConfig['url']) && $repoConfig['url'] !== '' ? $repoConfig['url'] : null;

if ($repoUrl === 'https://repo.packagist.org') {
$output->writeln(' - Packagist');
continue;
}

$output->writeln(sprintf(' - Composer (%s)', $repoUrl ?? 'no url?'));
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ComposerIntegration/PieJsonEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function revert(string $originalPieJsonContent): void
* Add a repository to the given `pie.json`. Returns the original
* `pie.json` content, in case it needs to be restored later.
*
* @param 'vcs'|'path' $type
* @param non-empty-string $url
* @param 'vcs'|'path'|'composer' $type
* @param non-empty-string $url
*/
public function addRepository(
string $type,
Expand Down
12 changes: 6 additions & 6 deletions test/integration/Command/RepositoryManagementCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setUp(): void

public function testPathRepositoriesCanBeManaged(): void
{
$this->assertRepositoryListDisplayed(['Packagist (cannot be removed)']);
$this->assertRepositoryListDisplayed(['Packagist']);

$this->addCommand->execute([
'type' => 'path',
Expand All @@ -56,17 +56,17 @@ public function testPathRepositoriesCanBeManaged(): void
$this->assertRepositoryListDisplayed(
[
'Path Repository (' . self::EXAMPLE_PATH_REPOSITORY_URL . ')',
'Packagist (cannot be removed)',
'Packagist',
],
);

$this->removeCommand->execute(['url' => self::EXAMPLE_PATH_REPOSITORY_URL]);
$this->assertRepositoryListDisplayed(['Packagist (cannot be removed)']);
$this->assertRepositoryListDisplayed(['Packagist']);
}

public function testVcsRepositoriesCanBeManaged(): void
{
$this->assertRepositoryListDisplayed(['Packagist (cannot be removed)']);
$this->assertRepositoryListDisplayed(['Packagist']);

$this->addCommand->execute([
'type' => 'vcs',
Expand All @@ -76,12 +76,12 @@ public function testVcsRepositoriesCanBeManaged(): void
$this->assertRepositoryListDisplayed(
[
'VCS Repository (' . self::EXAMPLE_VCS_REPOSITORY_URL . '.git)',
'Packagist (cannot be removed)',
'Packagist',
],
);

$this->removeCommand->execute(['url' => self::EXAMPLE_VCS_REPOSITORY_URL]);
$this->assertRepositoryListDisplayed(['Packagist (cannot be removed)']);
$this->assertRepositoryListDisplayed(['Packagist']);
}

/** @param list<non-empty-string> $expectedRepositories */
Expand Down
12 changes: 9 additions & 3 deletions test/unit/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ public function testListRepositories(): void
{
$output = new BufferedOutput();

$composerRepo = $this->createMock(ComposerRepository::class);
$packagistRepo = $this->createMock(ComposerRepository::class);
$packagistRepo->method('getRepoConfig')->willReturn(['url' => 'https://repo.packagist.org']);

$privatePackagistRepo = $this->createMock(ComposerRepository::class);
$privatePackagistRepo->method('getRepoConfig')->willReturn(['url' => 'https://repo.packagist.com/example']);

$githubRepoDriver = $this->createMock(GitHubDriver::class);
$githubRepoDriver->method('getUrl')->willReturn('https://github.com/php/pie');
Expand All @@ -201,7 +205,8 @@ public function testListRepositories(): void

$repoManager = $this->createMock(RepositoryManager::class);
$repoManager->method('getRepositories')->willReturn([
$composerRepo,
$packagistRepo,
$privatePackagistRepo,
$vcsRepo,
$pathRepo,
]);
Expand All @@ -214,7 +219,8 @@ public function testListRepositories(): void
self::assertSame(
<<<'OUTPUT'
The following repositories are in use for this Target PHP:
- Packagist (cannot be removed)
- Packagist
- Composer (https://repo.packagist.com/example)
- VCS Repository (https://github.com/php/pie)
- Path Repository (/path/to/repo)
OUTPUT,
Expand Down

0 comments on commit bb8a463

Please sign in to comment.