行の挿入/更新をテストするために、投稿をシミュレートし、リダイレクトされていることを確認し、新たに挿入/更新されたテキストがページにあることを確認するテストを作成しました。コードは機能しますが、テストではありません - なぜそれが間違っているのか教えてください。 IDパラメータを使用してインデックスページには、適切なテキストが含まれ、かつ主張Zend FrameworkとPHPUnitを使用してデータベースに行を追加する方法は、1つのユニットでどのようにテストされますか?
public function testEditProduct() {
$request = $this->getRequest();
$request->setMethod('POST');
$request->setPost(array(
'id'=>'1',
'title'=>'Test Product 1a'
));
$this->dispatch('/product/edit/id/1');
$this->assertRedirectTo('/');
$this->assertQueryContentContains('a', 'Test Product 1a');
}
public function testAddProduct() {
$request = $this->getRequest();
$request->setMethod('POST');
$request->setPost(array(
'title'=>'Test Product 3'
));
$this->dispatch('/product/add/');
$this->assertRedirectTo('/');
$this->assertQueryContentContains('a', 'Test Product 3');
}
次のテストの両方の仕事は、その製品のタイトルは、もはやページに表示されている製品を削除した後。あなたの最初のテストで
public function testIndexPageListsProducts() {
$this->dispatch('/product/index/id/1');
$this->assertQueryContentContains('h1', 'Test Product 1');
}
public function testDeleteProduct() {
$request = $this->getRequest();
$request->setMethod('POST');
$this->dispatch('/product/delete/id/2');
$this->assertRedirectTo('/');
$this->assertNotQueryContentContains('a', 'Test Product 2');
}