Skip to content

False positive in PHPStan 1.4.8 with assertNotSame with instances of the same class #120

@oliverklee

Description

@oliverklee

Using phpstan/phpstan-phpunit 1.0.0 and phpstan/phpstan 1.4.8, the following code creates a false positive:

namespace OliverKlee\Oelib\Tests\Unit\Templating;

use Nimut\TestingFramework\TestCase\UnitTestCase;
use OliverKlee\Oelib\Templating\Template;
use OliverKlee\Oelib\Templating\TemplateRegistry;

class TemplateRegistryTest extends UnitTestCase
{
    /**
     * @test
     */
    public function getForExistingTemplateFileNameCalledTwoTimesReturnsNewInstance(): void
    {
        self::assertNotSame(
            TemplateRegistry::get('EXT:oelib/Tests/Functional/Fixtures/Template.html'),
            TemplateRegistry::get('EXT:oelib/Tests/Functional/Fixtures/Template.html')
        );
    }
}

This is the error (with different line numbers):

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   Tests/Unit/Templating/TemplateRegistryTest.php                                                                                                           
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 
  69     Call to static method PHPUnit\Framework\Assert::assertNotSame() with OliverKlee\Oelib\Templating\Template and OliverKlee\Oelib\Templating\Template will  
         always evaluate to false.                                                                                                                                
  91     Call to static method PHPUnit\Framework\Assert::assertNotSame() with OliverKlee\Oelib\Templating\Template and OliverKlee\Oelib\Templating\Template will  
         always evaluate to false.                                                                                                                                
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 

This problem is new with PHPStan 1.4.8 (as it did no occur with PHPStan 1.4.7).

You can find the complete build with the problem at oliverklee/ext-oelib#904.

(I was not able to use the PHPStan playground for this as I currently do not know of any way of including PHPUnit in it: https://phpstan.org/r/c7fa7bda-1024-45c3-957d-7b91de41b844)

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