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

  1. First, create a directory structure for your extension:
    book
    └── cart
        ├── src
        └── features
  2. 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.