PHPackages                             ajant/db-mock-library - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ajant/db-mock-library

ActiveLibrary[Database &amp; ORM](/categories/database)

ajant/db-mock-library
=====================

Db mocking &amp; dummy data management library

2.1.0(9y ago)118.4k2[1 PRs](https://github.com/ajant/DbMockLibrary/pulls)MITPHPPHP &gt;=5.4.0

Since Mar 9Pushed 5y ago4 watchersCompare

[ Source](https://github.com/ajant/DbMockLibrary)[ Packagist](https://packagist.org/packages/ajant/db-mock-library)[ Docs](https://github.com/ajant/DbMockLibrary)[ RSS](/packages/ajant-db-mock-library/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (5)Versions (16)Used By (0)

DbMockLibrary
=============

[](#dbmocklibrary)

[![Build Status](https://camo.githubusercontent.com/be7f785f2f616c368f214be873f5ae30a7e3b1bedee258dbbda309a352cac3f5/68747470733a2f2f7472617669732d63692e6f72672f616a616e742f44624d6f636b4c6962726172792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ajant/DbMockLibrary)[![Coverage Status](https://camo.githubusercontent.com/253507b89e75a9da90b03a0a1667b504aec299bba411d01c2bbc018228dee649/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f616a616e742f44624d6f636b4c6962726172792f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/ajant/DbMockLibrary?branch=master)

Db mocking &amp; dummy data management library

[Wiki](https://github.com/ajant/DbMockLibrary/wiki)

This is a database stubbing/mocking/prototyping library. Its principal uses are meant to be:

1. testing the application without using actual database (by mocking data persistence layer, using DbMockLibrary)
2. quick prototyping, while delaying the writing of any database specific code (again by mocking data persistence layer, using DbMockLibrary)
3. dummy data management during development phase

Description:

1. If data persistence code is kept separate from business logic code, in a different layer of the application, then data persistence layer can be mocked using DbMockLibrary during testing. That way objects that call on data persistence layer can be tested, without actually using a real database. As a result tests are faster and better code &amp; test separation is achieved. DbMockLibrary could be used to mock data persistence layer functionality in the testing environment
2. When project is in prototyping stage, often making choice on database is not necessarily needed at that time. Sometimes it's even beneficial to postpone the decision for a while during that phase, until some features/architectural solutions take shape. What is needed is to have some "dummy data" available, to test out features and concepts with it. DbMockLibrary provides feature rich "dummy data" platform.
3. During development, it's often convenient to have some easy way to load/remove "dummy data" from the database, in order to be able to test out features, without having to create dumps from the production database. DbMockLibrary provides a simple way to manage this process for some of the most popular databases

Requirements
============

[](#requirements)

You'll need: PHP version 5.4+

Installation
============

[](#installation)

Install the latest version with composer:

```
require "ajant/db-mock-library": ~1

```

Auto-load the library:

```
use DbMockLibrary/DbMockLibrary
```

As of now MySQL, MongoDb and Elasticsearch databases have been implemented.

Quick start
===========

[](#quick-start)

Here's the example, how to use the library for testing DB features of the application.

**MySQL**
---------

[](#mysql)

Bootstrapping:

```
...
// 2 tables, 2 rows each
$data = [
    'table_1' => [
        -1 => ['foo' => 20, 'id' => -1],
        -2 => ['foo' => 50, 'id' => -2]
    ],
    'table_2' => [
        -1 => ['bar' => 30, 'id' => -1, 'table_1_id' => -1],
        -2 => ['bar' => 10, 'id' => -2, 'table_1_id' => -2]
    ]
];
// table_1_id is foreign key, referencing id column
$dependencies = [
    [
        DependencyHandler::DEPENDENT => ['table_2' => 'table_1_id'],
        DependencyHandler::ON        => ['table_1' => 'id']
    ]
];
// initialize MySQL
MySQL::initMySQL($data, 'localhost', 'DbMockLibraryTest', 'root', '', $dependencies);
...
```

Test set up:

```
...
// inserts both rows of table_2 and both rows of table_1, because
MySQL::getInstance()->setUp(['table_2' => [-1, -2]]);
...
```

Test tear down:

```
...
// removes all rows inserted during set up phase
MySQL::getInstance()->cleanUp();
...
```

**Elasticsearch**
-----------------

[](#elasticsearch)

Note:

It is presumed that all indexes and mappings for records that are to be used in testing are already in Elasticsearch database.

Bootstrapping:

```
...
// 4 indexes, 2 rows each
// 4th index is percolator index
$data = [
    'index_1' => [
        0 => ['foo' => 20, 'id' => -1],
        1 => ['foo' => 50, 'id' => -2],
    ],
    'index_2' => [
        0 => ['bar' => 30, 'id' => -1, 'index_1_id' => -1],
        1 => ['bar' => 10, 'id' => -2, 'index_1_id' => -2],
    ],
    'index_3' => [
        'record1' => ['field1' => 'value11', 'field2' => 'value12'],
        'record2' => ['field1' => 'value21', 'field2' => 'value22'],
    ],
    'index_4' => [
        'percolatorRecord1' => [
            'routing' => 0,
            'body' => [
                'query' => [
                    'bool' => [
                        'minimum_number_should_match' => 1,
                        'should' => [
                            [
                                'match' => [
                                    'someField' => [
                                        'query' => 'foo',
                                        'operator' => 'and'
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
        'percolatorRecord2' => [
            'routing' => 1,
            'body' => [
                'query' => [
                    'terms' => [
                        'someField' => [
                            'someValue'
                        ],
                    ],
                ],
            ],
        ],
    ],
];
// index_1_id is foreign key, referencing id column
$dependencies = [
    [
        DependencyHandler::DEPENDENT => ['index_2' => 'index_1_id'],
        DependencyHandler::ON        => ['index_1' => 'id'],
    ],
];
$indexTypes = [
    'index_1' => 'someType',
    'index_2' => 'someType',
    'index_3' => 'someType',
    'index_4' => '.percolator',
];
// initialize Elasticsearch
$client = \Elasticsearch\ClientBuilder::create()->setHosts(['http://localhost:9200'])->build();
Elasticsearch::initElasticsearch($client, $data, $dependencies, $indexTypes);
...
```

Test set up features:

```
...
// inserts both rows of index_2 and both rows of index_1, because
Elasticsearch::getInstance()->setUp(['index_2' => [0, 1]]);
// inserts all indexes
Elasticsearch::getInstance()->setUp();
// inserts only index_1
Elasticsearch::getInstance()->setUp(['index_1']);
...
```

Test tear down features:

```
...
// removes all rows inserted during set up phase, including dependencies
Elasticsearch::getInstance()->cleanUp();
// removes all indexes
Elasticsearch::getInstance()->tearDown();
// removes only index_1
Elasticsearch::getInstance()->tearDown(['index_1']);
...
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Recently: every ~145 days

Total

12

Last Release

3534d ago

Major Versions

0.2.3 → 1.0.02015-09-27

1.0.1 → 2.0.02016-01-05

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5788992?v=4)[Aleksandar Jovanovic](/maintainers/ajant)[@ajant](https://github.com/ajant)

---

Top Contributors

[![ajant](https://avatars.githubusercontent.com/u/5788992?v=4)](https://github.com/ajant "ajant (14 commits)")[![codespill](https://avatars.githubusercontent.com/u/22945611?v=4)](https://github.com/codespill "codespill (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ajant-db-mock-library/health.svg)

```
[![Health](https://phpackages.com/badges/ajant-db-mock-library/health.svg)](https://phpackages.com/packages/ajant-db-mock-library)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

27.6k172.1k9](/packages/bagisto-bagisto)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[elasticquent/elasticquent

Maps Laravel Eloquent models to Elasticsearch types.

1.4k957.8k2](/packages/elasticquent-elasticquent)[basemkhirat/elasticsearch

Laravel, Lumen and Native php elasticseach query builder to build complex queries using an elegant syntax

398314.1k](/packages/basemkhirat-elasticsearch)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[designmynight/laravel-elasticsearch

Use Elasticsearch as a database in Laravel to retrieve Eloquent models and perform aggregations.

3142.2k](/packages/designmynight-laravel-elasticsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
