测试__call方法

时间:2013-07-20 08:54:59

标签: php phpunit mockery

public function __call($method, $args)
{
    if ( ! in_array($method, $this->validMethods))
    {
      throw new \BadMethodCallException("Not a valid method: {$method}");
    }

}

如何测试__call方法以确保$method在我的有效方法列表中?现在这就是我所做的;

/**
 * @covers World\Transmission::__call()
 * @expectedException BadMethodCallException
 * @expectedExceptionMessage Not a valid method: foo
 */
public function test__callInvalidRequest()
{
    $m = m::mock('World\\Transmission', array($this->config))->makePartial();
    $m->foo(array('foo'));
}

我得到的错误是call_user_func_array()

的无尽痕迹
Maximum function nesting level of '100' reached, aborting!.
...

1 个答案:

答案 0 :(得分:1)

如何简单地将测试代码更改为:

    public function test__callInvalidRequest()
    {
        $transmission = new World\Transmission($this->config);
        $transmission->foo();
    }