Spark Plug is a special PHP library that returns Codeigniter applications as single variables. This package might be useful when testing applications to frameworks such as PHPUnit.
Install Spark Plug
through Composer:
$ composer require rougin/spark-plug
$ci = Rougin\SparkPlug\Instance::create();
// You can now use the CI_Controller instance
$ci->load->helper('inflector');
use Rougin\SparkPlug\SparkPlug;
$sparkplug = SparkPlug($GLOBALS, $_SERVER);
$ci = $sparkplug->instance();
$ci->load->helper('inflector');
use Rougin\SparkPlug\SparkPlug;
$sparkplug = SparkPlug($GLOBALS, $_SERVER);
// Sets the value of the APPPATH constant
$sparkplug->set('APPPATH', '/path/to/app');
$ci = $sparkplug->instance();
Available constants to be modified:
APPPATH
VENDOR
VIEWPATH
NOTE: If you set a new APPPATH
value, the value of VIEWPATH
will be set to APPPATH/views
.
use Rougin\SparkPlug\Instance;
class SampleTest extends \PHPUnit_Framework_TestCase
{
public function testCodeigniterInstance()
{
// Directory path to the test application
$application = __DIR__ . '/TestApp';
// Instance::create($path, $_SERVER, $GLOBALS)
$ci = Instance::create($application);
$this->assertInstanceOf('CI_Controller', $ci);
}
}
Please see CHANGELOG for more information what has changed recently.
$ composer test
The MIT License (MIT). Please see LICENSE for more information.