1. Go to this page and download the library: Download kenjis/ci-phpunit-test library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class Inventory_model_test extends TestCase
{
public function setUp(): void
{
$this->resetInstance();
$this->CI->load->model('Inventory_model');
$this->obj = $this->CI->Inventory_model;
}
public function test_get_category_list()
{
$expected = [
1 => 'Book',
2 => 'CD',
3 => 'DVD',
];
$list = $this->obj->get_category_list();
foreach ($list as $category) {
$this->assertEquals($expected[$category->id], $category->name);
}
}
public function test_get_category_name()
{
$actual = $this->obj->get_category_name(1);
$expected = 'Book';
$this->assertEquals($expected, $actual);
}
class Welcome_test extends TestCase
{
public function test_index()
{
$output = $this->request('GET', 'welcome/index');
$this->assertStringContainsString(
'<title>Welcome to CodeIgniter</title>', $output
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.