Skip to content

Commit

Permalink
Add test for filtering packages by url
Browse files Browse the repository at this point in the history
  • Loading branch information
onspli committed Sep 26, 2024
1 parent 28dd7bc commit 4efcf6d
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions tests/PackageSelection/PackageSelectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,143 @@ public function testSelect(array $expected, array $config, array $filterRepos =
self::assertEquals($expected, \array_keys($selected->getValue($selection)));
}

/**
* @return array<string, mixed>
*/
public function dataFilterRepos(): array
{
$packages = [
'alpha1' => [
'name' => 'vendor/project-alpha',
'version' => '1.2.3.1',
'source' => [
'url' => '[email protected]:vendor/project-alpha.git',
'type' => 'vcs',
'reference' => '1.2.3.1'
]
],
'alpha2' => [
'name' => 'vendor/project-alpha',
'version' => '1.2.3.2',
'source' => [
'url' => '[email protected]:vendor/project-alpha.git',
'type' => 'vcs',
'reference' => '1.2.3.2'
]
],
'beta1' => [
'name' => 'vendor/project-beta',
'version' => '1.2.3.1',
'source' => [
'url' => '[email protected]:vendor/project-beta.git',
'type' => 'vcs',
'reference' => '1.2.3.1'
]
],
'gamma1' => [
'name' => 'vendor/project-gamma',
'version' => '1.2.3.1',
'source' => [
'url' => '[email protected]:vendor/project-gamma.git',
'type' => 'vcs',
'reference' => '1.2.3.1'
]
],
];

$repo = [
'alpha_packages' => [
'type' => 'package',
'package' => [
$packages['alpha1'],
$packages['alpha2'],
]
],
'beta_packages' => [
'type' => 'package',
'package' => [
$packages['beta1'],
]
],
'gamma_packages' => [
'type' => 'package',
'package' => [
$packages['gamma1'],
]
],
];

foreach ($packages as &$p) {
$p = $p['name'] . '-' . $p['version'];
}

$data = [];

$data['Filter by one repository alpha'] = [
[
$packages['alpha1'],
$packages['alpha2'],
],
[
'repositories' => array_values($repo),
],
['[email protected]:vendor/project-alpha.git'],
];

$data['Filter by one repository beta'] = [
[
$packages['beta1'],
],
[
'repositories' => array_values($repo),
],
['[email protected]:vendor/project-beta.git'],
];

$data['Filter by two repositories'] = [
[
$packages['alpha1'],
$packages['alpha2'],
$packages['beta1'],
],
[
'repositories' => array_values($repo),
],
['[email protected]:vendor/project-beta.git', '[email protected]:vendor/project-alpha.git'],
];

return $data;
}

/**
* @dataProvider dataFilterRepos
*
* @param string[] $expected
* @param array<string, mixed> $config
* @param string[]|null $filterRepos
* @param string[]|null $filterPackages
*/
public function testFilterRepos(array $expected, array $config, array $filterRepos = null): void

Check failure on line 895 in tests/PackageSelection/PackageSelectionTest.php

View workflow job for this annotation

GitHub Actions / phpstan

PHPDoc tag @param references unknown parameter: $filterPackages
{

unset(Config::$defaultRepositories['packagist'], Config::$defaultRepositories['packagist.org']);

$composer = (new Factory())->createComposer(new NullIO(), $config, true, null, false);

$selection = new PackageSelection(new NullOutput(), 'build', $config, false);
$selection->setRepositoriesFilter($filterRepos);
$selection->setPackagesFilter([]);

$selection->select($composer, true);

$selectionRef = new \ReflectionClass(PackageSelection::class);
$selected = $selectionRef->getProperty('selected');
$selected->setAccessible(true);

\sort($expected, \SORT_STRING);
self::assertEquals($expected, \array_keys($selected->getValue($selection)));
}

/**
* @return array<string, mixed>
*/
Expand Down

0 comments on commit 4efcf6d

Please sign in to comment.