Skip to content

Commit

Permalink
fix: Add missing cast for the sort function of the requirement builder
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Mar 13, 2024
1 parent 70f998e commit 8304443
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/RequirementChecker/RequirementsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static function (array $sources): array {
usort(
$sources,
static fn (array $sourceTypePairA, array $sourceTypePairB) => strcmp(
$sourceTypePairA[0],
(string) $sourceTypePairA[0],
(string) $sourceTypePairB[0],
),
);
Expand Down
31 changes: 31 additions & 0 deletions tests/RequirementChecker/RequirementsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,40 @@ public function test_it_can_build_requirements_from_provided_extensions(): void
new Extension('http'),
'package2',
);
$this->builder->addProvidedExtension(
new Extension('http'),
null,
);

$expectedBuiltRequirements = new Requirements([]);
$expectedAllRequirements = new Requirements([
Requirement::forProvidedExtension('http', null),
Requirement::forProvidedExtension('http', 'package1'),
Requirement::forProvidedExtension('http', 'package2'),
]);

$this->assertBuiltRequirementsEquals($expectedBuiltRequirements);
$this->assertAllRequirementsEquals($expectedAllRequirements);
}

public function test_it_can_build_requirements_from_provided_extensions_sorting_edge_case(): void
{
$this->builder->addProvidedExtension(
new Extension('http'),
null,
);
$this->builder->addProvidedExtension(
new Extension('http'),
'package1',
);
$this->builder->addProvidedExtension(
new Extension('http'),
'package2',
);

$expectedBuiltRequirements = new Requirements([]);
$expectedAllRequirements = new Requirements([
Requirement::forProvidedExtension('http', null),
Requirement::forProvidedExtension('http', 'package1'),
Requirement::forProvidedExtension('http', 'package2'),
]);
Expand Down

0 comments on commit 8304443

Please sign in to comment.