I am running phpunit test on codeigniter, I have a admin_test.php file with this piece of code.
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);
}
}
And when I run the phpunit test I get this error.
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}()
I used composer to get phpunit test so following other tutorials wont work since composer is loading bootstrap.php file
Here is my phpunit.xml file
<?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>