CakePHP2でCakeResponseのstatusCodeをUnitTestする方法
$mockController = $this->generate('Posts');
$this->testAction('/posts/9999', array('method' => 'get'));
$this->assertEquals('404', $mockController->response->statusCode());モックコントローラーを作り、それを受け取って中にあるresponseプロパティからセットされたstatusCodeを取り出す。テストダブル方式ではないので、最終的にセットされた値しか取得できないが、まあこれで十分かな。
 
 
コメント / トラックバック