Codeception DB module addon for populate database

Overview

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 7.4 or higher.
  • Codeception 4.1 or higher.
  • Codeception Module DB 1.1 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:


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.

You might also like...
A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.

Eloquence Eloquence is a package to extend Laravel's base Eloquent models and functionality. It provides a number of utilities and classes to work wit

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

Laravel Migrations Generator Generate Laravel Migrations from an existing database, including indexes and foreign keys! Upgrading to Laravel 5.4 Pleas

[Package] Multi-tenant Database Schema Manager for Laravel

Multi-tenant Database Schema Manager for Laravel Tenanti allow you to manage multi-tenant data schema and migration manager for your Laravel applicati

Laravel 5 - Repositories to abstract the database layer

Laravel 5 Repositories Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain. See versions: 1.0.

A Redis based, fully automated and scalable database cache layer for Laravel
A Redis based, fully automated and scalable database cache layer for Laravel

Lada Cache A Redis based, fully automated and scalable database cache layer for Laravel Contributors wanted! Have a look at the open issues and send m

A php class for managing and connecting to a database

Query builder class php This class is responsible for creating and executing sql commands and helps you to execute as easily as possible and safely. I

Adminer database management tool for your Laravel application.

Laravel Adminer Adminer database management tool for your Laravel application. Table of Contents Introduction Features Installation CSRF token middlew

A mysql database backup package for laravel

Laravel Database Backup Package This package will take backup your mysql database automatically via cron job. Installing laravel-backup The recommende

Laravel Code Generator based on MySQL Database

Laravel Code Generator Do you have a well structed database and you want to make a Laravel Application on top of it. By using this tools you can gener

Releases(1.1.0)
Owner
Sergei Predvoditelev
Sergei Predvoditelev
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

SleekwareDB 12 Dec 11, 2022
The lightweight PHP database framework to accelerate development

The lightweight PHP database framework to accelerate development Features Lightweight - Less than 100 KB, portable with only one file Easy - Extremely

Angel Lai 4.6k Dec 28, 2022
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

The Laravel Components 2.5k Dec 27, 2022
ORM layer that creates models, config and database on the fly

RedBeanPHP 5 RedBeanPHP is an easy to use ORM tool for PHP. Automatically creates tables and columns as you go No configuration, just fire and forget

Gabor de Mooij 2.2k Jan 9, 2023
Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer

Spot DataMapper ORM v2.0 Spot v2.x is built on the Doctrine DBAL, and targets PHP 5.4+. The aim of Spot is to be a lightweight DataMapper alternative

Spot ORM 602 Dec 27, 2022
SQL database access through PDO.

Aura.Sql Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO,

Aura for PHP 533 Dec 30, 2022
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

CakePHP 4.3k Jan 7, 2023
Database management in a single PHP file

Adminer - Database management in a single PHP file Adminer Editor - Data manipulation for end-users https://www.adminer.org/ Supports: MySQL, MariaDB

Jakub Vrána 5.5k Jan 1, 2023
Doctrine Database Abstraction Layer

Doctrine DBAL 4.0-dev 3.0 2.13 N/A N/A Powerful database abstraction layer with many features for database schema introspection, schema management and

Doctrine 8.9k Dec 28, 2022
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Yan Ivanov 441 Dec 11, 2022