PHPUnit Testing

Step 1: Install ci-phpunit-test

Github page: link

With composer

From the root folder of your CodeIgniter application (where the application folder is in):

composer require kenjis/ci-phpunit-test --dev

Then run:

php vendor/kenjis/ci-phpunit-test/install.php

Upgrading via Composer

composer update kenjis/ci-phpunit-test

and:

php vendor/kenjis/ci-phpunit-test/update.php

Step 2: Install PHPUnit (Linux)

sudo apt-get install phpunit

Step 3: How to run tests

From the CodeIgniter application/tests folder:

phpunit

When $_SERVER variables are not found

In this case you can create a info.php file where you can list the contents of your local development server.

<?php
phpinfo();

Then you can modify the application/tests/phpunit.xml file by adding the following:

<php>
   <server name="HTTP_HOST" value="your.intranet.local"/>
   <server name="REQUEST_SCHEME" value="https"/>
   <server name="HTTPS" value="on"/>
   <server name="DOCUMENT_ROOT" value="/var/www/your-app/private_html"/>
</php>

You have to modify the values and required settings to your own needs.
For more information on this works see this link.

More steps (if not already done)

Install npm (linux)

Reference: link

sudo npm install npm -g

Install nodejs (linux)

Reference: link

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

followed by:

sudo apt-get install -y nodejs

and for the essentials:

sudo apt-get install -y build-essential

Install http-server (for showing coverages)

Reference: link

Install this on your development server, not your desktop linux

npm install http-server -g

Showing coverages from an intranet server

From a terminal go to the application/tests/build/coverages folder of your CodeIgniter application.
From there just type http-server. Now you can access the html page with the coverages from:

http://123.123.123.123:8080

where 123.123.123.123 is the right IP-address of your intranet server.

Last update: October 23rd at 10:15pm