0

I need to mock static method of class. But in phpunit:4 and later versions mocking static method is impossible (I get exception with message 'Static method "findBy" cannot be invoked on mock object'). How i need configure mock to get successful test?

I tried create mock class without phphunit manually. Somethig like tests/Mocks/MyClass.php that extends abstract class and implement my static method/

interface IdentityInterface
{
     // this method calling first in other component
    public static function findBy(string $number, ?string $trunk): ?IdentityInterface;
}

abstract class Identity implements IdentityInterface
{
    // this method and other calling after findBy method
    public function getName(): string
    {
        return $this->name; // need to cover
    }
}

My static method must return instance of itself to use other internal methods that i need to cover.

Kart Av1k
  • 137
  • 1
  • 6
  • Possible duplicate of [PHPunit mockobject abstract and static method](https://stackoverflow.com/questions/3247408/phpunit-mockobject-abstract-and-static-method) – Yassine CHABLI Feb 04 '19 at 14:33
  • @MohammedYassineCHABLI My method is not abstract and i can not create SomeIdentity class that extends Identity, because it is not provided for by the package structure. And also phpunit:3.5 is deprecated and i can not to use it for test static methods – Kart Av1k Feb 04 '19 at 14:49

0 Answers0