Unit testing with Behat
Behat is a BDD framework for testing your code with human-readable sentences that describes code behavior in various use cases.
Getting ready
Create an empty directory for a new project.
How to do it…
In this recipe, we will create a demonstration shopping cart extension with Behat tests.
Preparing extension structure
- First, create a directory structure for your extension:
book └── cart ├── src └── features
- To work with the extension as a Composer package, prepare the
book/cart/composer.json
file as follows:{ "name": "book/cart", "type": "yii2-extension", "require": { "yiisoft/yii2": "~2.0" }, "require-dev": { "phpunit/phpunit": "4.*", "behat/behat": "^3.1" }, "autoload": { "psr-4": { "book\\cart\\": "src/", "book\\cart\\features\\": ...
Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.