次の抽象クラスがあります。
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()
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
呼び出されるかわかりません..