0
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!.
...
4

1 回答 1

1

只需将您的测试代码更改为如下所示:

    public function test__callInvalidRequest()
    {
        $transmission = new World\Transmission($this->config);
        $transmission->foo();
    }
于 2013-07-20T10:15:51.040 回答