-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for filtering packages by url
- Loading branch information
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 GitHub Actions / phpstan
|
||
{ | ||
|
||
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> | ||
*/ | ||
|