Skip to content

[DeadCode] Remove whole assign statement on unused createStub() in tests - #8257

Merged
TomasVotruba merged 1 commit into
mainfrom
remove-unused-create-stub-assign
Aug 1, 2026
Merged

[DeadCode] Remove whole assign statement on unused createStub() in tests#8257
TomasVotruba merged 1 commit into
mainfrom
remove-unused-create-stub-assign

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

SideEffectNodeDetector already treats createMock() inside a PHPUnit\Framework\TestCase as side-effect free, so RemoveUnusedVariableAssignRector removes the whole statement. createStub() was not covered, so only the variable was dropped and a dangling call was left behind.

Before:

 final class SomeTest extends TestCase
 {
     public function test()
     {
-        $user = $this->createStub(User::class);
+        $this->createStub(User::class);
     }
 }

After:

 final class SomeTest extends TestCase
 {
     public function test()
     {
-        $user = $this->createStub(User::class);
     }
 }

@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 1, 2026 08:12
@TomasVotruba
TomasVotruba merged commit f6a25b2 into main Aug 1, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the remove-unused-create-stub-assign branch August 1, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant