Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/Composer/ArtifactsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public function activate(Composer $composer, IOInterface $io): void
return;
}

$this->artifacts = $this->addArtifactRepository($composer, $packagesDir);
$artifactsConfig = ['type' => 'artifact', 'url' => $packagesDir, 'canonical' => false];
$this->artifacts = $composer
->getRepositoryManager()
->createRepository('artifact', $artifactsConfig)
;

if (empty($this->artifacts->getPackages())) {
$this->artifacts = null;

if (null === $this->artifacts) {
return;
}

Expand All @@ -63,6 +69,10 @@ public function activate(Composer $composer, IOInterface $io): void
}

$this->registerProviders($requires);

// Prepend the artifacts repository after all providers
$composer->getRepositoryManager()->prependRepository($this->artifacts);
$composer->getConfig()->merge(['repositories' => [$artifactsConfig]]);
}

public function deactivate(Composer $composer, IOInterface $io): void
Expand Down Expand Up @@ -104,20 +114,6 @@ public static function getSubscribedEvents(): array
];
}

private function addArtifactRepository(Composer $composer, string $repositoryUrl): ?RepositoryInterface
{
$repository = $composer->getRepositoryManager()->createRepository('artifact', ['url' => $repositoryUrl]);

if (empty($repository->getPackages())) {
return null;
}

$composer->getRepositoryManager()->prependRepository($repository);
$composer->getConfig()->merge(['repositories' => [['type' => 'artifact', 'url' => $repositoryUrl]]]);

return $repository;
}

private function registerProviders(array $requires): void
{
$versionParser = new VersionParser();
Expand Down
29 changes: 21 additions & 8 deletions tests/Composer/ArtifactsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testAddsArtifactsRepositoryFromComposerDir(): void
$repositoryManager
->expects($this->once())
->method('createRepository')
->with('artifact', ['url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages'])
->with('artifact', ['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages', 'canonical' => false])
->willReturn($repository)
;

Expand All @@ -70,6 +70,7 @@ public function testAddsArtifactsRepositoryFromComposerDir(): void
[
'type' => 'artifact',
'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages',
'canonical' => false,
],
],
])
Expand All @@ -93,7 +94,7 @@ public function testAddsArtifactsRepositoryFromDataDir(): void
$repositoryManager
->expects($this->once())
->method('createRepository')
->with('artifact', ['url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages'])
->with('artifact', ['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages', 'canonical' => false])
->willReturn($repository)
;

Expand All @@ -112,6 +113,7 @@ public function testAddsArtifactsRepositoryFromDataDir(): void
[
'type' => 'artifact',
'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages',
'canonical' => false,
],
],
])
Expand Down Expand Up @@ -162,7 +164,7 @@ public function testDoesNotAddArtifactsRepositoryIfItHasNoPackages(): void
$repositoryManager
->expects($this->once())
->method('createRepository')
->with('artifact', ['url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages'])
->with('artifact', ['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages', 'canonical' => false])
->willReturn($repository)
;

Expand Down Expand Up @@ -190,8 +192,8 @@ public function testRegistersContaoProviders(): void
putenv('COMPOSER='.__DIR__.'/../Fixtures/Composer/artifact-data/composer.json');

$repositories = [
['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages'],
['type' => 'vcs', 'url' => 'https://example.org/'],
['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages', 'canonical' => false],
];

$config = $this->mockConfig(null);
Expand Down Expand Up @@ -323,7 +325,6 @@ public function testDoesNotRegisterDuplicateRepositories(): void
->expects($this->exactly(2))
->method('merge')
->withConsecutive(
[$this->arrayHasKey('repositories')],
[
$this->logicalAnd(
$this->arrayHasKey('repositories'),
Expand All @@ -334,7 +335,19 @@ public function testDoesNotRegisterDuplicateRepositories(): void
]],
])
),
]
],
[
$this->logicalAnd(
$this->arrayHasKey('repositories'),
$this->equalTo([
'repositories' => [[
'type' => 'artifact',
'url' => __DIR__.'/../Fixtures/Composer/provider-data/contao-manager/packages',
'canonical' => false,
]],
])
),
],
)
;

Expand Down Expand Up @@ -391,8 +404,8 @@ public function testDoesNotRegisterDuplicateRepositories(): void
public function testCorrectlyHandlesMultiplePackagesAndProviders(): void
{
$repositories = [
['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/provider-data/contao-manager/packages'],
['type' => 'vcs', 'url' => 'https://example.org/'],
['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/provider-data/contao-manager/packages', 'canonical' => false],
];

$config = $this->mockConfig(__DIR__.'/../Fixtures/Composer/provider-data/contao-manager');
Expand Down Expand Up @@ -487,7 +500,7 @@ public function testRegistersContaoProvidersFromRequireCommand(): void
putenv('COMPOSER='.__DIR__.'/../Fixtures/Composer/artifact-data/composer.json');

$repositories = [
['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages'],
['type' => 'artifact', 'url' => __DIR__.'/../Fixtures/Composer/artifact-data/contao-manager/packages', 'canonical' => false],
['type' => 'vcs', 'url' => 'https://example.org/'],
];

Expand Down