phpstan-phpunit
phpstan-phpunit copied to clipboard
StatementWithoutSideEffectsRule with expected exception shouldn't raise error
final class MyTest extends \PHPUnit\Framework\TestCase
{
public function testMe(): void
{
$foo = new class([1]) extends ArrayIterator {
public function current(): void
{
throw new RuntimeException('foo');
}
};
$this->expectException(\RuntimeException::class);
iterator_to_array($foo);
}
}
This code reports Call to function iterator_to_array() on a separate line has no effect., but while it's ok on production code (like in https://phpstan.org/r/ee6218f3-4d37-4b5a-9a85-bc6d6ab44d2b) , with PHPUnit is legit as for expectException expectation.
Hi, I don't know how to differentiate between legitimate and illegitimate use-cases, so feel free to just ignore this in the test case :)