diff --git a/src/RequirementChecker/RequirementsBuilder.php b/src/RequirementChecker/RequirementsBuilder.php index d8a5b4a2d..1cf8a9339 100644 --- a/src/RequirementChecker/RequirementsBuilder.php +++ b/src/RequirementChecker/RequirementsBuilder.php @@ -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], ), ); diff --git a/tests/RequirementChecker/RequirementsBuilderTest.php b/tests/RequirementChecker/RequirementsBuilderTest.php index f98cad507..a99cbef0f 100644 --- a/tests/RequirementChecker/RequirementsBuilderTest.php +++ b/tests/RequirementChecker/RequirementsBuilderTest.php @@ -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'), ]);