Setting up and using unit testing
To start using Unit testing in Zend Framework 2 can be a bit of a hassle. But don't worry; help is coming as we fly you through a proper set up of Zend Framework 2 unit testing.
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 on a couple of different ways but the easiest and 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 we now have an extra directory in our vendor directory called phpunit
.
How to do it...
Setting up unit testing...