Skip to content

Wrong types for assertIsNotNumeric #124

Open
@ZebulanStanphill

Description

@ZebulanStanphill

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.

Activity

ondrejmirtes

ondrejmirtes commented on Mar 17, 2022

@ondrejmirtes
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

ZebulanStanphill commented on Mar 17, 2022

@ZebulanStanphill
Author

@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

ondrejmirtes commented on Mar 21, 2022

@ondrejmirtes
Member

I confirm, it's a bug.

ondrejmirtes

ondrejmirtes commented on Mar 21, 2022

@ondrejmirtes
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Wrong types for `assertIsNotNumeric` · Issue #124 · phpstan/phpstan-phpunit