Cannot run phpunit test on codeigniter, CI not found error

I run phpunit test on codeigniter, I have admin_test.php file with this code snippet.

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 the composer to get the phpunit test, so the following other tutorials will not work since the composer is loading the 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>
+4
source share
2 answers

CI, . , function &get_isntance() system/core/CodeIgniter.php . , include ( , , vendor/autoload.php).

"" , , ( - index). , , get_instance - include , ( ), , 404 , , , . , . , (althoug, - ).

: CI bootrstraping, , , . CI - : - / , Codeception ( - ).

, . , CI - , .

( , CI, , , ( SO- ), . , , , .)

0
0

Source: https://habr.com/ru/post/1683182/


All Articles