我正在codeigniter上运行phpunit测试,我有一段admin_test.php文件与这段代码。无法在codeigniter上运行phpunit测试,CI未找到错误
class Admin_test extends PHPUnit_Framework_TestCase{
private $CI;
public function __construct()
{
// create instance variable
$this->CI = &get_instance();
}
public function testRenderReturnsHelloWorld(){
$this->CI->load->controller('admin');
$data = $this->admin->render();
$expected = 'Hello World';
$this->assertEquals($expected, $data);
}
}
而当我运行phpunit测试时,我得到这个错误。
PHP Fatal error: Call to undefined function get_instance() in C:\Users\farhana\Desktop\ci\tests\application\controllers\admin_test.php on line 16
PHP Stack trace:
PHP 1. {main}()
我用作曲家获得PHPUnit的测试,以便以下其他教程惯于因为作曲家作品加载的bootstrap.php文件
这里是我的phpunit.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="./vendor/autoload.php"
color = "true"
convertErrorsToExpections="true"
convertNoticesToExceptions="true"
convertWarningsToExpections="true"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Unit Tests">
<directory>./tests/application/controllers/admin_test.php</directory>
</testsuite>
</testsuites>
</phpunit>
我不确定,但也许类应该扩展CI_Controller? – Deblugger
@Deblugger我正在尝试运行phpunit测试,它无法扩展CI_Controller,那么单元测试将如何运行呢?当然我可以给它一个 – FaF
是的,但如果它不扩展CI_Controller我认为你不能使用Codeigniter函数 – Deblugger