I'm trying to apply PHPUnit in my project with CodeIgniter, based on the following example ( link ), until then when the installation and dependency files are all ok, only when I add setUp () method.
<?php
class ApiTest extends PHPUnit_Framework_TestCase {
private $CI;
public function setUp() {
$this->CI = &get_instance();
}
public function testVerifyFormat() {
$data = array(
"token" => "895c0d9b87d5ba256268f7238b61771e2b10291085ecb1015681817cb428fb66",
"updated_registries" => 30
);
$expected = json_encode($data, true);
$this->assertEquals(array_keys($data)[0], "token");
$this->assertEquals(array_keys($data)[1], "updated_registries");
$this->assertEquals(2, count($data));
}
}
It displays the following error:
Fatal error: "Call to undefined function get_instance()" in C:\xampp\htdocs\devops_ci\tests\ApiTest.php on line 7
Folder structure
- application
- assets
- system
- test (Bootstrap.php ApiTest.php)
- user_guide
- vendor (php folder downloaded after running composer.json)
- phpunit.xml
- index.php
I can run the tests, and I'm not able to reference the controllers
that are within application
, and by what I understood this method setUp () does just that.