Using Mockery as a mocking framework with PHPUnit

A few days ago I was explaining mocking to a few colleagues. I came up with the following quick n dirty code to show them the elegance of Mockery as a mocking framework.

The code is straight-forward: it checks the health of a server using a tiny heart beat script.

1. The script residing in the remote server:


2. The class that tries to fetch the status from the remote server:



A clean way of integrating PHPUnit 3.5.x with CodeIgniter 2.x

Now a days, my default choice of framework is always Zend Framework. However, I have to maintain a couple live projects in CodeIgniter from early days. I feel its very important to have tests around critical applications, so I have attempted a couple times to integrate PHPUnit with CodeIgniter but failed every time – well, until now.

I’ve managed it this time with hooks. It provides a clean way of bootstrapping the framework and then performing tests on the Model layer – for me testing the model layer has been sufficient. The use is very simple as it does not require any change in how a regular CodeIgniter application is built.

Grab the code from github.

Example – /tests/PostTest.php