2011-03-04 78 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) 
    ); 
}