Posted on

Reverse Engineering CodeIgniter, Sparks, to get CIUnit working

I ran into more issues with the spark for  cURL and the spark for Rest.
These are two awesome contributions by Phil Sturgeon to the CodeIgniter family.

Honestly this technology platform is way behind.  Node JS seems better equipped to manage packages with npm and nvm. And why do we have PEAR, PHAR, and Composer and a framework specific SPARK.  We are seeing the tower of babel problem when it comes PHP frameworks. Too many, too fast, the community has not congealed behind a single choice.
So developers from a huge PHP base are ending up being spread thin, some contributing to Yii, some on CodeIgniter, some on Laravel.

See if the programmers who made one of the other frameworks had worked as contributors to CodeIgniter, I probably would already have better CIUnit integration.

Anyway, so the problem was that the AutoLoader for PHPUnit command line execution of the project was being used twice! And somewhere in the first process, the sparks were added to an Array instance used to keep track of which sparks had been loaded.

Removing this, ‘duplicity’ check, made the application fail, because we were loading CURL twice. 1.2.0 spark and 1.2.1 spark were both being loaded and failing. So when I removed the duplicate CURL spark, the PHPUnit tests started to fly!

So I just put a CLI check in the function that removed duplications, in My_Loader.php:

# If we’ve already loaded this spark, bail
if(array_key_exists($spark_slug, $this->_ci_loaded_sparks)) {
if( php_sapi_name() != ‘cli’ )
return true;
}

 

This way, if and only if I am executing this CodeIgniter project on the command line, will sparks be loaded freely.