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'), + [], + ], ], ); } 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,