psalm-plugin-phpunit icon indicating copy to clipboard operation
psalm-plugin-phpunit copied to clipboard

Suppress UnusedFunctionCall, UnusedMethodCall when test expects an exception

Open vudaltsov opened this issue 4 years ago • 1 comments

Consider this case:

<?php

use PHPUnit\Framework\TestCase;

final class JsonDecodeTest extends TestCase
{
    public function testThrowsOnInvalidJson(): void
    {
        $this->expectException(\JsonException::class);

        // UnusedFunctionCall is thrown here
        json_decode('', flags: JSON_THROW_ON_ERROR);
    }
}

I am not sure that this is doable or worth the effort, so feel free to close the issue. For now we just suppressed UnusedFunctionCall and UnusedMethodCall in psalm.xml for the whole tests directory.

vudaltsov avatar Mar 31 '21 10:03 vudaltsov

It's doable (the plugin already suppresses MissingConstructor), but I'm wondering whether people would complain about false-negatives :thinking:

weirdan avatar Mar 31 '21 12:03 weirdan