我有一些使用夹具的 PHPUnit 测试类。我定义了 10 个表固定装置。目录结构:
tests
fixtures
table1.php
...
table10.php
unit
MyTestClass.php
我现在有一个测试类 ( MyTestClass.php
),我只想填充其中的 2 个表。我在那个类中有以下代码。
class BaseACAExportTest extends CDbTestCase
{
public $fixtures = array(
'table1' => 'Model1',
'table2' => 'Model2'
);
public function setUp()
{
// Call the parent setUp to set up the fixtures
parent::setUp();
die();
}
public testMe()
{
// Test here
}
}
该函数TruncateDatabase
是一个定制的辅助函数,它截断所有 10 个表。我已验证此功能有效。我运行测试并在die
语句之后检查数据库。在其中,我看到了所有 10 个表,而不仅仅是我在fixtures
. 为什么它会填充目录中定义的所有表fixtures
?有没有办法绕过这个?