From b151b4b6c4d542ba03ba1a2a534b4224da3113e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Wed, 13 Mar 2024 08:28:21 +0100 Subject: [PATCH] fix: Add missing cast for the sort function of the requirement builder (#1335) --- .../RequirementsBuilder.php | 2 +- .../RequirementsBuilderTest.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) 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'), ]);