rectorphp / rector-phpunit

Rector upgrade rules for PHPUnit
https://getrector.com/find-rule?activeRectorSetGroup=phpunit
MIT License
68 stars 47 forks source link

`AddDoesNotPerformAssertionToNonAssertingTestRector` incorrectly adds `@doesNotPerformAssertions` annotation #165

Closed Wirone closed 1 year ago

Wirone commented 1 year ago

Consider test method and its related methods:

public function testSomething(): void
{
    $this->mockSomething(); // This makes assertion internally by using `MockObject::expects()`
    $this->runSomething(true);
}

private function mockSomething(): void
{
    $this->something // This is mock prepared in setUp()
        ->expects(self::once())
        ->method('handle');
}

Currently AddDoesNotPerformAssertionToNonAssertingTestRector adds @doesNotPerformAssertions annotation to such tests, which is not true. Method itself does not have assertion calls, but other method(s) called within test makes assertions with MockObject::expects().

TomasVotruba commented 1 year ago

Fixed in https://github.com/rectorphp/rector-phpunit/pull/211