dpl9717 2019-02-04 14:23
浏览 97

如何在PHP中用phpunit测试抽象类的静态方法

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了