面对Simpletest中Fixtures创建的障碍

时间:2015-02-17 09:31:34

标签: php unit-testing cakephp-1.3 simpletest

我是Simpletest的初学者,在创建灯具时遇到问题。因为我正在为我的应用程序使用cakephp 1.3.14版本。

  1. 使用文件名complaints_fixture.php创建的灯具

    class ComplaintFixture extends CakeTestFixture {
    
        var $name = 'Complaint';
        var $import = array('table' => 'complaints', 'records' => true);
    
        // do not truncate movie_stars table between tests
        public function truncate($db) {
            return null;
        }
    
        // do not drop movie_stars table between tests
        public function drop($db) {
            return null;
        }
    
    }
    
  2. 创建名为complaint.test.php的测试用例

    App::import('Model', 'Complaint');
    
    class ComplaintTestCase extends CakeTestCase {
    
        var $fixtures = array('app.Complaint');
    
        function setUp($method) {
            parent::setUp();
            $this->Complaint = & ClassRegistry::init('Complaint');
    
            // load data
            $this->loadFixtures('Complaint');
        }
    
        function testFixture() {
            $numberOfResults = $this->Complaint->find('count');
            var_dump($numberOfResults);
        }
    
        /*
          function testupdateComplaintStatus(){
          $result = $this->Complaint->updateComplaintStatus(47,'ACT');
          $this->assertEqual($result,1,'Status updated successfully!');
          } */
    }
    
  3. 正如您在上面的代码中看到的那样,使用名称Complaint创建一个fixture,然后使用测试用例来加载该fixture。所以,我从开发者指南中读到的内容 - 我们创建一个夹具,指定字段名称和记录集 - 在测试模型类中加载该fixture。

    但是,我正在寻找的是对正在插入测试数据库的测试数据执行CRUD操作。并且,当我尝试使用上面给出的脚本执行相同操作时,它会开始影响生产数据库记录而不是测试数据库。

    如果您在上面的代码中看到我甚至停止了 truncate drop 以获取测试数据,但却无法解决问题。

    有人能让我知道上面代码中遗漏了什么吗?

0 个答案:

没有答案