A Codeception extension for facilitating easy dumps.
Laxative makes managing the dump file from the Codeception Db module a snap. It's particularly useful for teams with rapidly changing data models. Laxative eliminates the need for developers maintaining the dump file by always starting from scratch. Laxative will use the developers local codebase to create a fresh database for testing.
- Codeception 1.6.4
- PHP 5.4
Installation using Composer
$ composer require jonpitch/laxative
Be sure to enable the extension in
codeception.yml as shown in
All enabling and configuration is done in
extensions: enabled: - Codeception\Extension\Laxative config: Codeception\Extension\Laxative: backup: true|false backup_path: 'path/to/your/backup/file.backup' host: 'database host IP|URL' database: 'database-name' login: 'database-login' migrations: 'your migrate command' seed: 'your seed command'
Laxative needs a consistent point to start from. The easiest way to do this is to leverage the Codeception Db module to do this for us.
- Create an empty database
- Create a dump file, for example:
pg_dump -h 192.168.10.10 -d my-database -U my-user
- Configure your Codeception Db module to use this empty database
- Enable backup and restore your database before and after a suite runs.
- Default: false
- Relative path to store your database backup.
- The location of your database.
- Example: '192.168.1.10'
- The name of your database.
- The database user login.
- A command to execute database migrations.
- Example: 'php artisan migrate'
- A command to populate your database with data.
- Example: 'php artisan db:seed'
Once installed and enabled, before and after any suite with the Db module enabled, Laxative will:
- Backup your local database (if enabled)
- Use Codeception Db to restore from your empty database (see above)
- Run your migrations command
- Run your seed command
- Re-configure your Db module to use the fresh dump file.
Your tests will then run as normal from a fresh database. If you have the
backup option enabled, when the suite is finished your database will be restored to how it was before the tests.
- For now, Laxative is specific to Postgres. If you require something different, issue a pull request or send me an email.