Unit testing

Unit testing

Writing proper tests can assist in writing better software. If you set up proper test cases you can eliminate most functional bugs and better maintain your software.

Integrating PHPunit with phalcon

If you don’t already have phpunit installed, you can do it by using the following composer command:

composer require phpunit/phpunit:^5.0

or by manually adding it to composer.json:

{
    "require-dev": {
        "phpunit/phpunit": "^5.0"
    }
}

Once phpunit is installed create a directory called ‘tests’ in your root directory:

app/
public/
tests/

Next, we need a ‘helper’ file to bootstrap the application for unit testing.

The PHPunit helper file

A helper file is