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

allow plugin to continue operating if `assert()` is non-fatal

Open SignpostMarv opened this issue 5 years ago • 3 comments

In some environments, assert() can be configured to be non-fatal, which causes the plugin to error out when $param->type is passed to a function that expects Type\Union.

Setting the type via Type::getMixed() (being the equivalent of "unknown" in this particular case) allows the plugin to continue executing, while the assertion still gets logged.

When assertions are fatal, no change in behaviour is expected as the plugin should bail out right away.

SignpostMarv avatar Jan 12 '20 10:01 SignpostMarv

incidentally, this looks like it closes #32

SignpostMarv avatar Jan 12 '20 12:01 SignpostMarv

I think the issue should be addressed by removing the assert and dealing with the situation that causes failure (and for that we need a reproducer, as was requested in https://github.com/psalm/phpunit-psalm-plugin/issues/32#issuecomment-506999621), rather than trying to work it around. Ideally we should not modify Psalm-inferred types in the plugin, so it's better to clone them if we have to.

weirdan avatar Jan 12 '20 23:01 weirdan

~@weirdan found a public project that generates the issue during rebasing, will see if it sticks around after I'm done.~ nope, it went away; while rebasing, came across a commit that renamed a parameter on the method but the docblock wasn't updated (bad rebase?), so:

  • there was a tag for a non-existent parameter $foo
  • the method had an untyped $_foo

ERROR: InvalidDocblockParamName - tests\unit\LiveMailboxTest.php:370:18 - Incorrect param name $expected_compose_result in docblock for PhpImap\LiveMailboxTest::test_append_nudges_mailbox_count /** * @dataProvider AppendProvider * * @depends test_append * * @param string $expected_compose_result * @param bool $pre_compose * * @psalm-param MAILBOX_ARGS $mailbox_args * @psalm-param COMPOSE_ENVELOPE $envelope * @psalm-param COMPOSE_BODY $body */

ERROR: MissingParamType - tests\unit\LiveMailboxTest.php:381:3 - Parameter $_expected_compose_result has no provided type $_expected_compose_result,

SignpostMarv avatar Feb 05 '20 01:02 SignpostMarv