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

Call to method PHPUnit\Framework\Assert::assertSame() with {int} and int will always evaluate to false. #64

Open
teohhanhui opened this issue Feb 19, 2020 · 1 comment

Comments

@teohhanhui
Copy link

Given this class:

<?php
declare(strict_types=1);

namespace ApiPlatform\Core\Identifier\Normalizer;

use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

final class IntegerDenormalizer implements DenormalizerInterface
{
    public function denormalize($data, $class, $format = null, array $context = []): int
    {
        return (int) $data;
    }
}

And calling assertSame like this:

<?php

declare(strict_types=1);

namespace ApiPlatform\Core\Tests\Identifier\Normalizer;

use ApiPlatform\Core\Identifier\Normalizer\IntegerDenormalizer;
use PHPUnit\Framework\TestCase;

class IntegerDenormalizerTest extends TestCase
{
    public function testDenormalize()
    {
        $this->assertSame(2, (new IntegerDenormalizer())->denormalize('2', 'int'));
    }
}

Gives an error such as:

 ------ ----------------------------------------------------------------------------------------------------- 
  Line   tests/Identifier/Normalizer/IntegerDenormalizerTest.php                                              
 ------ ----------------------------------------------------------------------------------------------------- 
  26     Call to method PHPUnit\Framework\Assert::assertSame() with 2 and int will always evaluate to false.  
 ------ -----------------------------------------------------------------------------------------------------
@ondrejmirtes ondrejmirtes transferred this issue from phpstan/phpstan-phpunit Mar 3, 2020
@ondrejmirtes ondrejmirtes transferred this issue from phpstan/phpstan Mar 3, 2020
@mabar
Copy link

mabar commented Feb 15, 2022

I ran into the same issue with assertSame()

use PHPUnit\Framework\TestCase;

final class Test extends TestCase
{
	public function test(): void
	{
		touch('/file');
		$handle = fopen('/file', 'rwb');
		self::assertSame(0, fwrite($handle, 'data'));
		self::assertSame('data', fread($handle, 2));
	}
}
Call to static method PHPUnit\Framework\Assert::assertSame() with 0 and int<0, max>|false will always evaluate to true.
Call to static method PHPUnit\Framework\Assert::assertSame() with 'data' and string|false 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