我仍在为测试我的Symfony2控制器编写PHP单元测试。我的测试类是WebTestCase的派生类,测试会进行GET或POST请求来检查一切是否正常。 我想测试所有底层层次,但又不想用测试来破坏我的数据库。我也不想使用模拟,而是使用内存中的SQLite数据库,在其中设置一个测试场景以检查所有修改。 我发现很多如何使用Doctrine 1.x进行此操作的提示,但它们不再起作用。 因此,我想要像这样的东西:
class BlahblahTest extends WebTestCase {
public function testXXXYYY() {
// 1. Setup a new database with SQLite:memory:
// 2. create the database and all tables according the entities in my project
$this->createTestScenario(); // 3.
$crawler = $this->client->request('GET', '/testpage'); // 4.
// 5. Lots of checks against the database and / or the $crawler data
}
}
有没有可能完成这项工作?
提前感谢 Hennes
memory: true
并明确设置path: ":memory:"
,否则您将会从 Symfony 和 Doctrine 中得到投诉。 - tftd