【问题标题】:Call to undefined function get_instance in codeigniter在 codeigniter 中调用未定义的函数 get_instance
【发布时间】:2013-11-24 07:22:06
【问题描述】:

我使用 Simpletest 编写了一个测试类。这是我的 PHP 代码:

<?php
  require_once '../simpletest/autorun.php';
  class Exam extends UnitTestCase {
    private $CI;
    function testUser() {
      $this->CI = & get_instance();
      $this->CI->load->model('user_model');
      $this->assertTrue($this->CI->user_model->listAll());
    }
  }

但是当我执行这个脚本时。有一个错误:

Fatal error: Call to undefined function get_instance() in 
D:\xampp\htdocs\simpleCI\test\exam.php on line 10

为什么 get_instance 未定义,我怎样才能使它可用?

【问题讨论】:

  • 你有没有收到并回答过这个问题?

标签: codeigniter simpletest


【解决方案1】:

Simpletest 不是 CodeIgniter 的一部分。扩展 UnitTestCase 不会从 CI 继承任何东西。或许你可以试试这个库:https://github.com/ericbarnes/codeigniter-simpletest

【讨论】:

  • 谢谢你的回答,我已经用过了,但是我不知道怎么用,但是当我运行文件 test_users_model.php 时,我遇到了另一个问题:致命错误:找不到类'CodeIgniterUnitTestCase' D:\xampp\htdocs\simpleCI\tests\models\test_users_model.php 在第 3 行而且我不知道如何用 simpletest 编写一个简单的测试。请给我看一个小测试演示好吗?
猜你喜欢
  • 2014-03-25
  • 1970-01-01
  • 2016-04-06
  • 2012-02-16
  • 2018-05-05
  • 2017-03-01
  • 2015-10-05
  • 1970-01-01
  • 2023-01-02
相关资源
最近更新 更多