我有以下抽象类:
abstract class Voter
{
public function vote()
{
$this->something();
$this->something();
$this->voteFoo();
$this->voteBar();
}
public function __call($method, $args)
{
//...
}
abstract public function something();
}
voteFoo
并由voteBar
处理__call
。
我想断言同时vote()
调用voteFoo()
and voteBar()
,我该怎么做?
我尝试使用$this->at(..)
,但它给了我一个错误:
$voter = $this->getMockForAbstractClass('Voter', array(), '', true, true, true, array('__call'));
$voter->expects($this->any())
->method('something')
->will($this->returnValue(true));
$voter->expects($this->at(0))
->method('__call')
->with($this->equalTo('voteFoo'));
$voter->expects($this->at(1))
->method('__call')
->with($this->equalTo('voteBar'));
$voter->vote();
*********** ERROR *************
Expectation failed for method name is equal to <string:__call> when invoked at
sequence index 0.
Mocked method does not exist.
编辑:
如果我将值更改$this->at()
为2和3,则测试通过,这意味着由于某种原因$this->something()
也会触发该__call
方法。
这个Voter类不是我真正的Voter类,它是问题的简单版本。__call
在我真正的课堂上,我不知道会被调用多少次..