Skip to content

Repository files navigation

CodeIgniter PHPUnit Test


CodeIgniter 3 PHPUnit Test extension library

Latest Stable VersionLicense

This RESTful API extension is collected into yidas/codeigniter-pack which is a complete solution for Codeigniter framework.

FEATURES

  • PHPUnit Test in Codeigniter 3 Framework

  • Easy to install into your Codeigniter project by Composer


OUTLINE

REQUIREMENTS

This library requires the following:

  • PHP 5.3.0+
  • CodeIgniter 3.0.0+

INSTALLATION

Run Composer in your Codeigniter project under the folder \application:

composer require yidas/codeigniter-phpunit

DIRECTORY STRUCTURE

codeigniter/
└── application/
├── tests/ Test cases
├── vendor/ Vendor included yidas/codeigniter-phpunit
└── phpunit.xml PHPUnit XML

CONFIGURATION

According to Directory Structure, create and configure phpunit.xml under application directory:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunitbootstrap="vendor/yidas/codeigniter-phpunit/bootstrap.php">
<testsuites>
<testsuitename="TestSuite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

For this phpunit.xml template, the test cases directory is application/test, make sure you would create every test cases under it.


USAGE

In the application directory of this library, run phpunit from vendor:

$ ./vendor/bin/phpunit

Or using absolute path commands like:

$ /var/www/html/codeigniter3/application/vendor/bin/phpunit -c /var/www/html/codeigniter3/application/phpunit.xml
$ phpunit -c /var/www/html/codeigniter3/application/phpunit.xml

Then the result would like:

PHPUnit5.7.27bySebastianBergmannandcontributors.Time:40ms,Memory:2.75MBNotestsexecuted!

TEST CASE

With this extension libaray, you could write test cases with loading Codeigniter framework.

For example, write a test case application/tests/CodeigniterTest.php for testing Codeigniter config component:

<?phpusePHPUnit\Framework\TestCase;
finalclass CodeigniterTest extends TestCase
{
function__construct() {
parent::__construct();
// Load CI application$this->CI = & get_instance();
}
publicfunctiontestConfigItem()
{
$indexPage = $this->CI->config->item('index_page');
$this->assertSame('index.php', $indexPage);
}
}

Then you would get the result OK (1 test, 1 assertion) by running PHPUnit test.

About

CodeIgniter 3 PHPUnit Test extension library

Topics

Resources

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages