我正在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