phpstan-phpunit icon indicating copy to clipboard operation
phpstan-phpunit copied to clipboard

StatementWithoutSideEffectsRule with expected exception shouldn't raise error

Open Slamdunk opened this issue 5 years ago • 1 comments

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.

Slamdunk avatar Oct 26 '20 15:10 Slamdunk

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 :)

ondrejmirtes avatar Oct 26 '20 15:10 ondrejmirtes