0
Zendフレームワークを使用したユニットテストのテストケースを開発しています。コンポーザーを使用してPHPUnitをインストールしました。私はWindowsプラットフォームで作業しています。PHPユニットテスト:テストケースの実行中に擬似メソッドがトリガされない
私は方法を模擬しようとしています。テストケースを実行している間、模擬メソッドは呼び出されません。代わりに私はシステム定義の方法で試しましたが、期待通りにうまく動作しています。
コード下記参照してください:
/* Class CommonDataHandlerTest */
class CommonDataHandlerTest extends PHPUnit_Framework_TestCase{
public function mockTestCall(){
return 'foo';
}
}
class Apps_Sample_DataHandlerTest extends CommonDataHandlerTest{
public function setUp() {
....
}
public function tearDown() {
....
}
/*But here the method mockTestCall is not triggering while executing */
public function testReturnCallbackStub() {
$observer = $this->getMockBuilder('Apps_Sample_DataHandler')
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->getMock();
$that = $this;
$observer->method('getSampleData')
->will($this->returnCallback(
function() use($that) {
$that->mockTestCall();
}
));
$this->assertEquals('foo', $observer->getSampleData());
}
/*This is method is working as expected*/
public function testReturnCallbackStubSystem() {
$observer = $this->getMockBuilder('Apps_Sample_DataHandler')
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->getMock();
$observer->method('getSampleData')
->will($this->returnCallback('str_rot13'));
$this->assertEquals('foo', $observer->getSampleData('ssb'));
}
}
上記のコード、テストケースメソッドの実行時に「testReturnCallbackStubSystem」期待通りに動作しています。
しかし、テストケースメソッド 'testReturnCallbackStub'は機能しません。ここで嘲笑されたメソッド 'mockTestCall'はトリガーされません。
私はその理由をご存知ですか? 誰か助けてください。それ以上の詳細が必要なら、私に知らせてください。事前に
おかげで...