Download the PHP package dbx12/yii2-mock-database without Composer
On this page you can find all versions of the php package dbx12/yii2-mock-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dbx12/yii2-mock-database
More information about dbx12/yii2-mock-database
Files in dbx12/yii2-mock-database
Package yii2-mock-database
Short Description Mock connection for the Yii2 database connection. This connection can be configured to fail operations for testing purposes.
License MIT
Informations about the package yii2-mock-database
Mock database failures for Yii 2
This library provides adapted connections and command classes for Yii2 database connections. With it, you can force database failures in your tests to check how your application behaves when the database is not reachable for example.
Setup and usage
- Install with
composer require --dev dbx12/yii2-mock-database
- Define the
\dbx12\yii2MockDatabase\Connection
class as your database connection class. - During the tests, call
Yii::$app->db->failAlways()
to fail all subsequent commands. Make sure you've loaded your fixtures before doing that. - Return to normal behavior by calling
Yii::$app->db->passAlways()
- Optionally register the CleanupExtension in your phpunit.xml to get rid of old
mockDatabase.dat
files (see below)
Other methods
failNextCommand($count = 1)
allows you to only fail a given number of commands and then return to "normal behavior"passNextCommand($count = 1)
allows you to only pass a given number of commands and then return to "always fail"
Cleanup Extension
The cleanup extension deletes all files given to it in the first argument after the last test. You can use it to clean
your output directory and prevent old files from affecting future test runs. All paths must be either absolute or
relative to the working directory of phpunit. A configuration example is in the code block below, it assumes your working
directory is the project root (you call phpunit as vendor/bin/phpunit
).