测试许多场景 - 从测试方法手动插入测试DB

时间:2016-03-03 12:02:27

标签: php phpunit

我想根据不同的数据库初始状态测试控制器方法内发生的所有事情。问题是我必须在一次测试中拥有许多不同的初始数据库集,然后测试不同的输出。例如:

public function testSomeAction() {
   $sc = new SomeController();

   $user = new User(1, null, date('Ymd'));
   $sc -> someAction();
   $this -> assertTrue(1, $this -> getConnection() -> getRowCount('user'));

   $user = new User(1, 'aaa', null);
   $sc -> someAction();
   $this -> assertTrue(0, $this -> getConnection() -> getRowCount('user'));
}

等等。在我需要添加数据库输入并且在我的代码中没有insert方法之前没关系 - 然后我必须将它包含在数据集中。但我不想要这个,因为我在其他测试中使用相同的数据集。

所以问题是 - 我可以从测试方法手动插入测试数据库吗?

0 个答案:

没有答案