Fixtures
The last testing component we'll talk about in this chapter is fixtures. Fixtures are an important part of testing as they enable us to set up our application state to a known and precise state before running our unit tests. Unlike these other test types, however, fixtures are provided directly by Yii2 and integrate into Codeception via the Yii2 Codeception module.
Tip
In this section, we'll be using the source code on the fixtures
branch located at https://github.com/masteringyii/chapter10.
Creating fixtures
To get started with using fixtures, we first need to install the required composer dependencies and then add some configuration to our config/console.php
file:
First, we need to make sure that the
yii2-faker composer
package is installed:$ composer require --dev yii2-faker
Alternatively, the
yii2-faker
extension can be installed by adding the following to therequire-dev
section ofcomposer.json
and then by executingcomposer update
:"yiisoft/yii2-faker": "*",
Then, we need to add...