Skip to content

Call to static method PHPUnit\\Framework\\Assert::assertSame() with SomeSingleton and SomeSingleton will always evaluate to true. #3134

@nusje2000

Description

@nusje2000

I wrote a test for a singleton class which tests the following:

Class method:

public static function getInstance(): SomeSingleton {
        if (null === static::$instance) {
            static::$instance = new static();
        }

        return static::$instance;
}

Test method:

public function testGetInstance(): void {
    self::assertSame(SomeSingleton::getInstance(), SomeSingleton::getInstance());
}

With this code I could understand the error from occurring but when I changed the code in the singleton to this:

public static function getInstance(): SomeSingleton {
       return new static();
}

The error still occurred even while the assertSame was now evaluating to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions