Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong types for assertIsNotNumeric #124

Open
ZebulanStanphill opened this issue Mar 17, 2022 · 4 comments
Open

Wrong types for assertIsNotNumeric #124

ZebulanStanphill opened this issue Mar 17, 2022 · 4 comments

Comments

@ZebulanStanphill
Copy link

ZebulanStanphill commented Mar 17, 2022

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.

@ondrejmirtes
Copy link
Member

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
Copy link
Author

ZebulanStanphill commented 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
Copy link
Member

I confirm, it's a bug.

@ondrejmirtes
Copy link
Member

But it's not related to the 2nd arg, it reproduces even without it:

+'09: Call to static method PHPUnit\Framework\Assert::assertIsNotNumeric() with non-empty-string will always evaluate to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants