A small utility package that allows Codeigniter 3 applications as single variables.
A special package that returns an application based on Codeigniter 3 as a single variable. Might be useful when testing a Codeigniter 3
project to frameworks such as PHPUnit.
Install Spark Plug
through Composer:
$ composer require rougin/spark-plug
Instance
helper$ci = Rougin\SparkPlug\Instance::create();
// You can now use the CI_Controller instance
$ci->load->helper('inflector');
[!NOTE] Instead of
CI_Controller
, it returnsRougin\SparkPlug\Controller
for type-hinting its helpers and libraries.
SparkPlug
classuse Rougin\SparkPlug\SparkPlug;
$sparkplug = new SparkPlug($GLOBALS, $_SERVER);
$ci = $sparkplug->instance();
// The Inflector helper is now loaded ---
$ci->load->helper('inflector');
// --------------------------------------
use Rougin\SparkPlug\SparkPlug;
$sparkplug = new SparkPlug($GLOBALS, $_SERVER);
// Set the value of the APPPATH constant ---
$sparkplug->set('APPPATH', '/path/to/app');
// -----------------------------------------
$ci = $sparkplug->instance();
Available constants that can be modified:
APPPATH
VENDOR
VIEWPATH
[!NOTE] If setting a new
APPPATH
value, the value ofVIEWPATH
will be set toAPPPATH/views
.
CI_Controller
for unit testinguse 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);
}
}