All Projects → vjik → codeception-db-populator

vjik / codeception-db-populator

Licence: BSD-3-Clause license
Codeception DB module addon for populate database

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to codeception-db-populator

appium-driver-codeception
Appium Driver for codeception
Stars: ✭ 19 (+0%)
Mutual labels:  codeception
symfony-skeleton
Skeleton rest-api based on symfony
Stars: ✭ 15 (-21.05%)
Mutual labels:  codeception
Codeception
Full-stack testing PHP framework
Stars: ✭ 4,401 (+23063.16%)
Mutual labels:  codeception
codeception
▶️ Integration of Nette Framework to Codeception.
Stars: ✭ 27 (+42.11%)
Mutual labels:  codeception
Crud
CRUD PORTO Containers for apiato and Angular2 modules generator, based on Laravel 5.4 and Angular 2.4+
Stars: ✭ 23 (+21.05%)
Mutual labels:  codeception
allure-codeception
Codeception framework adapter for Allure
Stars: ✭ 43 (+126.32%)
Mutual labels:  codeception
codeigniter-tettei-apps
『CodeIgniter徹底入門』のサンプルアプリケーション(CodeIgniter v3.1版)
Stars: ✭ 26 (+36.84%)
Mutual labels:  codeception
jdbdt
JDBDT: Java Database Delta Testing
Stars: ✭ 12 (-36.84%)
Mutual labels:  database-testing
irontest
A web app for API test automation
Stars: ✭ 31 (+63.16%)
Mutual labels:  database-testing

Database Populator for Codeception DB Module


Latest Stable Version Total Downloads Build status static analysis License

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.

Requirements

  • PHP 8.0 or higher.
  • Codeception 5.0 or higher.
  • Codeception Module DB 3.0 or higher.

Installation

The package could be installed with composer:

composer require vjik/codeception-db-populator --dev --prefer-dist

General usage

Enable module Db and DatabasePopulator 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 format table => rows. For example:

<?php
return [
    '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:

final class BlogTest extends Unit
{
    public function testCreatePost(): void
    {
        $this->tester->loadDump('blog');
        $this->tester->loadRows('authors');
        ...
    }
}

Actions

loadDump()

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

loadRows()

Load the specified row set(s) to database.

$I->loadRows('posts'); // load one set
$I->loadRows('users', 'comments'); // load several sets

Configuration

  • 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.

Testing

Unit and integration testing

The package is tested with Codeception. 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

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The Database Populator for Codeception DB Module is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].