CakePHPモックオブジェクトでセッションコンポーネントに値が入力されていることをテストしようとしていますが、書き込みメソッドが呼び出されていないことを示すテストが失敗し続けます。私はこれをデバッグし、メソッドが呼び出されたという事実を知っているので、私が間違っていることを確かめないでください。ここでCakePHPユニットモックコントローラのテスト
は、ユニットテストのコードです:
$this->controller = $this->generate('Posts', array(
'components' => array(
'Session' => array('write')
)));
$this->testAction(...);
$this->controller->Session
->expects($this->any())
->method('write')
->with('my value here');
私は次のエラーを取得:私はあることを期待への呼び出しを変更した場合
Expectation failed for method name is equal to when invoked zero or more times. Mocked method does not exist.
を - >(の$ this - >を期待します)(1回)私は、このエラーを取得:、
Expectation failed for method name is equal to when invoked 1 time(s). Method was expected to be called 1 times, actually called 0 times.
は私がコントローラー>の$ this - 上のvar_dumpをした、と嘲笑セッションオブジェクトは間違いありそれは 'write'メソッドへの呼び出しに気付くように見えるので、なぜ私がエラーメッセージを受け取っているのか本当にわかりません。
アドバイスをいただければ幸いです!あなたの問題を解決する必要があり
$this->controller = $this->generate('Posts', array(
'components' => array(
'Session' => array('write')
)));
//Add the method mock details here
$this->controller->Session
->expects($this->any())
->method('write')
->with('my value here');
//Then call testAction
$this->testAction(...);
:
あなたはどのバージョンのCakePHPを使用していますか? – Farray
私はCakePHP 2.0.4を使用しています – rikkyc