Unit testing with PHPUnit
PHPUnit is the most popular PHP testing framework. It is simple for configuration and usage. Also, the framework supports code coverage reports and has a lot of additional plugins. Codeception from the previous recipe uses PHPUnit for own work and writing unit tests. In this recipe, we will create a demonstration shopping cart extension with PHPUnit tests.
Getting ready
Create a new yii2-app-basic
application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guidestart-installation.html.
How to do it…
First, we must create a new empty directory for own extension.
Preparing extension structure
- First, create the directory structure for your extension:
book └── cart ├── src └── tests
To work with the extension as a Composer package, prepare the
book/cart/composer.json
file like this:{ "name": "book/cart", "...