- Notifications
You must be signed in to change notification settings - Fork0
Codeception DB module addon for populate database
License
vjik/codeception-db-populator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Codeception DB module addon that helps you to tune database populations.So for a test you could load only needed tables or rows. As a result it dramatically reduces the total execution time.
- PHP 8.0 or higher.
- Codeception 5.0 or higher.
- Codeception Module DB 3.0 or higher.
The package could be installed withcomposer:
composer require vjik/codeception-db-populator --dev
Enable moduleDb
andDatabasePopulator
addon in the suite:
modules:enabled: -Db:dsn:'mysql:host=%DB_HOST%;dbname=%DB_NAME%'user:'%DB_USERNAME%'password:'%DB_PASSWORD%' -Vjik\Codeception\DatabasePopulator\Module:dumpsPath:'tests/_data/dumps'rowsPath:'tests/_data/rows'
Create SQL dumps that contains a record of the table structure and/or the data for use in tests.Put dumps into path, specified in options (for example,tests/_data/dumps
).
Create row sets for populate database tables. Row sets is PHP file that return array in formattable => rows
.For example:
<?phpreturn ['author' => [ ['id' =>1,'name' =>'Ivan', ], ['id' =>2,'name' =>'Petr', ], ],'post' => [ ['id' =>1,'author_id' =>2,'name' =>'First post', ], ['id' =>2,'author_id' =>2,'name' =>'My history', ], ],];
You can get structure, similar to this:
tests/ _data/ dumps/ user-management.sql blog.sql catalog.sql rows/ users.php authors.php blog-categories.php posts-with-categories.php
Load dumps and row sets in your tests:
finalclass BlogTestextends Unit{publicfunctiontestCreatePost():void {$this->tester->loadDump('blog');$this->tester->loadRows('authors');... }}
Load the specified dump(s) to database. Before loading the dump, the database is cleaned.
$I->loadDump('blog');// load one dump$I->loadDump('blog','catalog');// load several dumps
Load the specified row set(s) to database.
$I->loadRows('posts');// load one set$I->loadRows('users','comments');// load several sets
dumpsPath
(required) — relative path to directory with dumps (for example,tests/_dump
).rowsPath
(required) — relative path to directory with row sets (for example,tests/_rows
).preloadDump
— dump(s) for preload before run suite.preloadRows
— row set(s) for preload before run suite.
The package is tested withCodeception. For tests need MySQL database with configuration:
- host:
127.0.0.1
- name:
db_test
- user:
root
- password:
root
To run tests:
./vendor/bin/codecept run
The code is statically analyzed withPsalm. To run static analysis:
./vendor/bin/psalm
The Database Populator for Codeception DB Module is free software. It is released under the terms of the BSD License. Please seeLICENSE
for more information.
About
Codeception DB module addon for populate database
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.