From e65bc0303cac7ebc9e676363fb8f844d9b28d598 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Mon, 28 Nov 2022 11:02:54 +0100 Subject: [PATCH 1/2] Add testcase for covaraint interface which is failing --- ...ParameterTypeContravarianceChangedTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php index 01e902ff..f83dabaa 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php @@ -88,6 +88,13 @@ static function changed1($a, $b) {} function changed2($a, $b) {} } } + +namespace N5 { + interface A {} + class C { + public function changed(A $a) {} + } +} PHP , $astLocator, @@ -126,6 +133,14 @@ static function changed1(int $a, int $b) {} function changed2(int $a, int $b) {} } } + +namespace N5 { + interface A extends B {} + interface B {} + class C { + public function changed(B $a) {} + } +} PHP , $astLocator, @@ -185,6 +200,11 @@ function changed2(int $a, int $b) {} '[BC] CHANGED: The parameter $b of N4\C#changed2() changed from no type to a non-contravariant int', ], ], + 'N5\C#changed' => [ + self::getMethod($fromReflector->reflectClass('N5\C'), 'changed'), + self::getMethod($toReflector->reflectClass('N5\C'), 'changed'), + [], + ], ], ); } From 7bc674cb654b43aed9b242e13bcda3b363ec72b7 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Mon, 28 Nov 2022 14:14:07 +0100 Subject: [PATCH 2/2] Add TestCase for TypeIsContravariant --- .../Variance/TypeIsContravariantTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php b/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php index 9c57d1f9..6b438733 100644 --- a/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php +++ b/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php @@ -562,6 +562,46 @@ public function existingNullableTypeStrings(): array ]; } + public function testContravarianceWhereClassWasMissingBefore(): void + { + $astLocator = (new BetterReflection())->astLocator(); + + $fromLocator = new StringSourceLocator( + <<<'PHP' +reflectClass('Service')->getMethod('__invoke')->getParameter('a')->getType(), + (new DefaultReflector($toLocator))->reflectClass('Service')->getMethod('__invoke')->getParameter('a')->getType() + )); + } + private static function identifierType( Reflector $reflector, ReflectionProperty $owner,