如何测试在其他类内部创建的对象上调用的方法?

时间:2019-01-09 09:04:49

标签: php laravel testing mocking

我正在使用laravel 5.5。而且我需要测试是否在对象(在其他类内部创建)上调用了某种方法。我该怎么办?

示例:

class A {
    public static function createQuery($variable){
        $b = new B($variable);
        if($variable === 1){
            $b->withShoes();
        }
        if($variable === 2){
            $b->withSocks();
        }
        if($variable === 1 || $variable === 3){
            $b->withFriends();
        }
        return $b->get();
    }
}

class B {
    public function withShoes(){
        ...
    }
    public function withSocks(){
        ...
    }
    public function withFriends(){
        ...
    }
    public function get(){
        ...
    }
}

我想做这样的测试:调用withShoes()时是否调用了方法A::createQuery($variable)?感谢您的帮助。

0 个答案:

没有答案