From 3323b3fb2444467a4bb8a068cd08693130f0c20b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 28 Jan 2026 12:05:07 +0100 Subject: [PATCH] add failing fixture for setup only used property --- .../Fixture/nested_callback.php.inc | 2 +- .../skip_nested_variable_from_uses.php.inc | 2 +- .../Fixture/some_test.php.inc | 63 +++++++++++++++++++ .../MockToStubSetupCombinedTest.php | 28 +++++++++ .../Source/MockedClass.php | 7 +++ .../Source/SomeClassWithArguments.php | 12 ++++ .../config/configured_rule.php | 13 ++++ 7 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 tests/Issues/MockToStubSetupCombined/Fixture/some_test.php.inc create mode 100644 tests/Issues/MockToStubSetupCombined/MockToStubSetupCombinedTest.php create mode 100644 tests/Issues/MockToStubSetupCombined/Source/MockedClass.php create mode 100644 tests/Issues/MockToStubSetupCombined/Source/SomeClassWithArguments.php create mode 100644 tests/Issues/MockToStubSetupCombined/config/configured_rule.php diff --git a/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/nested_callback.php.inc b/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/nested_callback.php.inc index 1e1bb134..a38f250a 100644 --- a/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/nested_callback.php.inc +++ b/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/nested_callback.php.inc @@ -38,7 +38,7 @@ final class NestedCallback extends TestCase $this->someMock->expects($matcher) ->method('prepare') ->willReturnCallback( - function (...$parameters) use ($matcher) { + function (...$parameters) use ($matcher, $item) { if ($matcher->numberOfInvocations() === 1) { $this->assertEquals(50, $parameters[0]); $this->assertSame(5, $parameters[1]); diff --git a/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/skip_nested_variable_from_uses.php.inc b/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/skip_nested_variable_from_uses.php.inc index 18426458..61f22c3d 100644 --- a/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/skip_nested_variable_from_uses.php.inc +++ b/rules-tests/PHPUnit100/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/skip_nested_variable_from_uses.php.inc @@ -32,7 +32,7 @@ final class SkipNestedVariableFromUses extends TestCase $this->someMock->expects($matcher) ->method('prepare') ->willReturnCallback( - function (...$parameters) use ($matcher) { + function (...$parameters) use ($matcher, $item) { $this->assertSame(5, $parameters[0]); }, ); diff --git a/tests/Issues/MockToStubSetupCombined/Fixture/some_test.php.inc b/tests/Issues/MockToStubSetupCombined/Fixture/some_test.php.inc new file mode 100644 index 00000000..0e5a7fd3 --- /dev/null +++ b/tests/Issues/MockToStubSetupCombined/Fixture/some_test.php.inc @@ -0,0 +1,63 @@ +someMock = $this->createMock(MockedClass::class); + + $generator = new RewindableGenerator(fn () => yield from [ + $this->someMock, + ], 2); + } + + public function testSomething(): void + { + } + + public function testAnother(): void + { + } +} + +?> +----- +createMock(MockedClass::class); + + $generator = new RewindableGenerator(fn () => yield from [ + $someMock, + ], 2); + } + + public function testSomething(): void + { + } + + public function testAnother(): void + { + } +} + +?> diff --git a/tests/Issues/MockToStubSetupCombined/MockToStubSetupCombinedTest.php b/tests/Issues/MockToStubSetupCombined/MockToStubSetupCombinedTest.php new file mode 100644 index 00000000..ea599222 --- /dev/null +++ b/tests/Issues/MockToStubSetupCombined/MockToStubSetupCombinedTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/MockToStubSetupCombined/Source/MockedClass.php b/tests/Issues/MockToStubSetupCombined/Source/MockedClass.php new file mode 100644 index 00000000..efdc9199 --- /dev/null +++ b/tests/Issues/MockToStubSetupCombined/Source/MockedClass.php @@ -0,0 +1,7 @@ +withRules(rules: [ + NarrowUnusedSetUpDefinedPropertyRector::class, + BareCreateMockAssignToDirectUseRector::class, + ]);