2011-03-04 38 views
2

我一直在尝试,但徒劳无功,在cakePhP中创建了多个灯具。目前,我需要测试一个需要两个不同灯具数据库表的函数。如果可能的话,有人可以发布一些简单的代码片段,并让我创建多个设备。在cakePhp中创建多个灯具pixelp

回答

4

炉,

你采取一看蛋糕的bake效用?你可以用它来烘烤灯具。

cake bake fixture all 

在您的应用程序中一次烘烤所有灯具。小心使用以免覆盖现有代码。

Edit0: 使用

cake bake fixture help 
如果您还有其他问题

4

这里有一个简单的夹具:应用程序/测试/夹具/ 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) 
    ); 
}