【发布时间】:2011-07-09 01:48:40
【问题描述】:
我一直在尝试在 cakePhP 中创建多个固定装置,但没有成功。目前,我需要测试一个需要两个不同夹具数据库表的功能。如果可能的话,有人可以发布一些简单的 sn-p 并告诉我创建多个固定装置。
【问题讨论】:
标签: cakephp
我一直在尝试在 cakePhP 中创建多个固定装置,但没有成功。目前,我需要测试一个需要两个不同夹具数据库表的功能。如果可能的话,有人可以发布一些简单的 sn-p 并告诉我创建多个固定装置。
【问题讨论】:
标签: cakephp
熔炉,
你看过 cake 的 bake 实用程序吗?你可以用它烘焙灯具。
cake bake fixture all
在您的应用中一次烘焙所有固定装置。小心使用,以免覆盖现有代码。
编辑0: 使用
cake bake fixture help
如果您还有其他问题。
【讨论】:
这是一个简单的夹具:app/tests/fixtures/entity_fixtures.php 在您的情况下,您将创建两个这样的文件,每个模型一个并且具有不同的名称。
<?php
class EntityFixture extends CakeTestFixture {
var $name = 'Entity';
var $table = 'entities';
// Define the fields
var $fields = array(
'entity_id' => array('type' => 'integer', 'key' => 'primary'),
'type' => array('type' => 'string' , 'length' => 255),
'created' => 'datetime',
'modified' => 'datetime'
);
var $records = array(
array('entity_id' => 1, 'type' => 'entity', 'created'=>'2010-01-01', 'modified' => '2010-01-01')
);
}
?>
在您的测试用例中,在测试用例的顶部包含您的固定装置
class EntityTestCase extends CakeTestCase {
var $fixtures = array(
'plugin.myplugin.entity', // Including a sample plugin fixture
'entity', // The fixture above shown in code above
'blogs' // Including a third fixture (should be in app/tests/fixtures/blog_fixture.php)
);
}
【讨论】: