Unit testing – why would you do it
Unit testing is a form of testing that has been widely accepted in the programming world. Unfortunately a lot of PHP developers still lack the knowledge on how to utilize it to their benefit, or they just don't know how to get started. This recipe will try to change that.
Getting ready
To get started with Unit testing a Zend Framework 2 application, it is required that we have PHPUnit 3.7.x installed. We can do this in a couple of different ways, but the easiest and most recommended way is by installing it through Composer, which comes with the Zend Framework 2 application.
To install PHPUnit through Composer we just need to add the following lines to composer.json
:
{ "require-dev": { "phpunit/phpunit": "3.7.*" } }
After saving the composer.json
file, run Composer to update the new requirements.
$ php composer.phar update
After a short while, the Composer installer will be complete and we will be ready to begin creating our unit tests. We can see that...