データベーステストのオペレーション

このエントリーをはてなブックマークに追加
はてなブックマーク - データベーステストのオペレーション
Share on Facebook

PHPUnitを使ってDBと連携したテストする際には、PHPUnitのDatabaseTestという拡張を使います。この場合よくあるケースとして、setUp()でテーブルにフィクスチャを入れ、tearDown() でDBを掃除したいことがあります。

そうした処理には、オペレーションと呼ばれるメソッドを使うと便利です。下記にその一覧を書いておきます。

メソッドの詳細は、「\PEAR\PHPUnit\Extensions\Database\Operation\Factory.php」に書いてあります。

オペレーション やる内容
NONE() 何もしない
CLEAN_INSERT() TRUNCATE→INSERT
INSERT() データセットを挿入する
TRUNCATE() Executes a truncate against all tables in a dataset.
DELETE() Deletes the rows in a given dataset using primary key columns.
DELETE_ALL() Deletes all rows from all tables in a dataset.
UPDATE() Updates the rows in a given dataset using primary key columns.

参考

Chapter 9. Database Testing

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>