2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHPでテスト自動実行

Last updated at Posted at 2016-04-03

Cake2.xでのテストモジュールを使う

公式ドキュメント だとUnixで動かすことが前提なので、備忘録をかねてメモする

  1. xampp\php上で、cmd.exeから phpunit --version とコマンドを入力し、何らかのバージョン番号が帰ってくることを確認する。
    image
  2. バージョン番号が確認できない場合、xampp\phpにファイルphpunitの存在を確認した上で、なければ、(https://phar.phpunit.de/)からphpunit.pharをダウンロードし、phpunitと名前を変えて保存
  3. テスト用データベースを設定し、database.phpを編集する
public $test = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host'       => 'dbhost',
    'login'      => 'dblogin',
    'password'   => 'dbpassword',
    'database'   => 'test_database'
);
  1. ウェブランナー http://localhost/[appname]/test.php にアクセスして、こんな画面が表示されれば成功
    • image
  2. ディレクトリ app/Test/Case/[Type]というディレクトリに、○○○Test.phpというファイルを作成し、CakeTestCase、または ControllerTestCase, PHPUnit_Framework_TestCaseを継承したクラスを作る

エラーの対応 PHPUnit_Framework_TestCase::__construct() must be of the type array

  • こちらは何のこと無い、テストクラスに Testをつけていなかったため、controllerと同じクラス名になってしまっていた。テストクラスを生成しようとしてもControllerを継承していなかったので上記の感じなエラーとなった
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?