Undefined method on mock object implementing a given interface in PHPUnit?

前端 未结 3 2115
夕颜
夕颜 2021-02-07 04:34

I\'m new to unit testing and PHPUnit.

I need a mock, on which I have a full control, implementing ConfigurationInterface interface. Test subject is Re

3条回答
  •  花落未央
    2021-02-07 05:25

    Tyler Collier's warning is fair but doesn't contain a code snippet on how to code around it. Note this is very nasty and you should fix the interface instead. With that warning added:

    $methods = array_map(function (\ReflectionMethod $m) { return $m->getName();}, (new \ReflectionClass($interface))->getMethods());
    $methods[] = $missing_method;
    $mock = $this->getMock($interface,  $methods);
    

提交回复
热议问题