CakePHP2 での testAction
- CakePHP1.3 コントローラーのテスト(testAction なし バージョン)
の続きを書こうとして、ふと「2.0-phpunit」ブランチが気になって、コミットを追った。
その結果、testAction ありバージョンの意味が分からなくなった。
CakePHP2(「2.0-phpunit」ブランチ) のコミットを見る
- 2010-05-04
- メソッド名変更「testAction」-> 「runTestAction」
- http://github.com/cakephp/cakephp/commit/14559aabd9b545c40790aa0e8074fddbad0ab3e0
- 2010-05-05
- testAction メソッドと関連コードを削除。
- 「Removing code from CakeTestCase around the method "testAction" which was a bad way of testing controllers, often making it more difficult.This also removes class contamination in newly created test cases」
- http://github.com/cakephp/cakephp/commit/bed87b87c69533afab09e7e52cf28bfa79e85335
- 2010-06-20 までのコミットには、関連はなし。
→ testAction どうなるのかわからん。でも、url → ディスパッチ → コントローラー → モデルやビュー をまとめて行うテストは欲しい。
simpletest でのリダイレクトテスト
モックオブジェクトを作って、メソッドがコールされているかを調べる。
http://github.com/cakephp/cakephp/blob/1ec220dac26109648936dd267d8040ceb20cffaf/cake/tests/cases/libs/controller/controller.test.php#L917
PHPUnit
PHPUnit にもモックオブジェクトを作成する機能があり、simpletest の部分はこちらに置き換わっている。
http://www.phpunit.de/manual/3.5/en/test-doubles.html#test-doubles.mock-objects