Open
Description
The following TestCase will cause PHPStan to report a false positive.
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @phpstan-return non-empty-string
*/
function someFunction(): string {
return '10';
}
final class MyTest extends TestCase {
public function testGeneration(): void {
self::assertIsNotNumeric(
someFunction(),
'This expectation message is misinterpreted as the "actual" param.'
);
}
}
The false positive:
Call to static method PHPUnit\Framework\Assert::assertIsNotNumeric() with non-empty-string and 'This expectation…' will always evaluate to true.
Metadata
Metadata
Assignees
Labels
No labels
Activity
ondrejmirtes commentedon Mar 17, 2022
I don't get it - in my opinion PHPStan is right, that string is not numeric which means the assert will always pass. Which means you can delete that line, the test is useless.
ZebulanStanphill commentedon Mar 17, 2022
@ondrejmirtes Sorry, that example was over-simplified from my actual use case. The actual use case involves calling a function that returns a
non-empty-string
. I've updated the example to be slightly closer to the real thing.Also, as you can see in the error message, it's comparing the wrong string.
ondrejmirtes commentedon Mar 21, 2022
I confirm, it's a bug.
ondrejmirtes commentedon Mar 21, 2022
But it's not related to the 2nd arg, it reproduces even without it: