これは私のテストです:
public function testIncludeNumComment() {
$post = array(...stuff.....);
$result = $this->Comments->includeNumComments($post);
echo "end"; //this is not printed
$expected =1;
$this->assertEquals($result, $expected);
}
次に、私のコントローラー関数は次のとおりです。
public function includeNumComments($post){
echo "printed";
$comments = $this->Comment->getNumComments($post['Post']['id']);
echo "not printed";
return $comments;
}
ご覧のとおり、コントローラーでのモデル関数への呼び出しは機能しません。
$this->Comment->getNumComments($idPost);
さらに、エコー「こんにちは」を紹介すると、Comment モデル内のgetNumComments関数の最初の部分でも出力されません。機能などを見つけられなかったようです。(ただし、テスト中は画面ごとにエラーは表示されません)
そこで停止し、それ以上コードを実行しません。関数がうまく機能することは完全に確信しています。投稿からコメントの数を返すだけです。問題は、なぜテストケースで機能しないのですか?
ありがとう。
更新: テストのセットアップは次のようになります。
public function setUp() {
parent::setUp();
$this->Comments = new TestCommentsController();
$this->Comments->constructClasses();
}