-
-
Notifications
You must be signed in to change notification settings - Fork 742
Closed
rectorphp/rector-phpunit
#656Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | 2.3.6 |
AllowMockObjectsForDataProviderRector & AllowMockObjectsWithoutExpectationsAttributeRector are applied on stub usage when they should only be applied on mock usage. This seems to only happen when stub is setup in setUp method.
Minimal PHP Code Causing Issue
https://getrector.com/demo/457a19c3-f0d0-4d4f-9a44-a567c8250736
<?php
use PHPUnit\Framework\TestCase;
+#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
final class FooTest extends TestCase
{
private ClassToStub $foo;
public function setUp(): void
{
parent::setUp();
$foo = self::createStub(\ClassToStub::class);
$foo->method('foo')->willReturn('error');
$this->foo = $foo;
}
public function test()
{
$this->foo->foo();
}
}
class ClassToStub
{
public function foo(): string
{
return 'error';
}
};Expected Behaviour
Rector should not apply the rule
Reactions are currently unavailable