diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/double_instance_order.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/double_instance_order.php.inc new file mode 100644 index 00000000..3c7dd530 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/double_instance_order.php.inc @@ -0,0 +1,63 @@ +getSomeObject(); + $someNestedObject = $someObject->getSomeNestedObject(); + + $this->assertSame(123, $someNestedObject->getNumber()); + } + + private function getSomeObject(): ?SomeClassUsedInTests + { + if (mt_rand(0, 1)) { + return new SomeClassUsedInTests(); + } + + return null; + } +} + +?> +----- +getSomeObject(); + $this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); + $someNestedObject = $someObject->getSomeNestedObject(); + $this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeNestedObject::class, $someNestedObject); + + $this->assertSame(123, $someNestedObject->getNumber()); + } + + private function getSomeObject(): ?SomeClassUsedInTests + { + if (mt_rand(0, 1)) { + return new SomeClassUsedInTests(); + } + + return null; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeClassUsedInTests.php b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeClassUsedInTests.php index 0c1bd934..87973f74 100644 --- a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeClassUsedInTests.php +++ b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeClassUsedInTests.php @@ -10,4 +10,9 @@ public function getSomeMethod(): int { return 1000; } + + public function getSomeNestedObject(): ?SomeNestedObject + { + return new SomeNestedObject(); + } } diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeNestedObject.php b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeNestedObject.php new file mode 100644 index 00000000..a5ac7c7a --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Source/SomeNestedObject.php @@ -0,0 +1,13 @@ +