PHPackages                             bancer/paratest-databases-factory - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. bancer/paratest-databases-factory

ActiveLibrary[Testing &amp; Quality](/categories/testing)

bancer/paratest-databases-factory
=================================

Creates test databases for running PHP unit tests in parallel

0.9.2(4y ago)04.2k↓100%MITPHPPHP &gt;=5.6

Since Nov 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/bancer/paratest-databases-factory)[ Packagist](https://packagist.org/packages/bancer/paratest-databases-factory)[ RSS](/packages/bancer-paratest-databases-factory/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

paratest-databases-factory
==========================

[](#paratest-databases-factory)

This library provides a convinient way to automate the creation of test databases and is supposed to be used when running PHP unit tests in parallel. It is compatible with paratest library - .

How to install
--------------

[](#how-to-install)

Execute `composer require bancer/paratest-databases-factory` or `composer require bancer/paratest-databases-factory --update-no-dev` to install by composer.

How to use
----------

[](#how-to-use)

Create test databases in bootstrap.php:

```
use Bancer\ParatestDatabasesFactory\DatabasesFactory;
...
(new DatabasesFactory())
    ->setDsn(getenv('pf_dsn'))
    ->setUsername(getenv('pf_user'))
    ->setPassword(getenv('pf_pass'))
    ->createDatabase('pf_test');
```

This will create pf\_test1, pf\_test2 etc. test databases when unit tests are started. The database name and credentials are just an example here. The requirement is that the user has permissions to connect to the database and has been granted the privilege to create databases.

Load the bootstrap file in phpunit.xml file if not already done, f.ex.: ``.

Create the database user and grant privileges to create databases:

```
CREATE USER 'pf_user'@'%' IDENTIFIED BY 'your_password';
GRANT CREATE ON *.* TO 'pf_user'@'%';
CREATE DATABASE pf_test;
GRANT SELECT ON `pf_test`.* TO 'pf_user'@'%';
```

Add the database credentials to phpunit.xml:

```

```

Adjust your database configuration by appending `TEST_TOKEN` environment variable value. Something like this:

```
if (getenv('TEST_TOKEN') !== false) { // Using paratest
    $databaseName .= getenv('TEST_TOKEN');
}
```

There are two ways how to run phpunit tests in parallel:

1. By using plain phpunit.

    - Pros:
        - No dependencies to third party libraries.
        - Can be implemented with any version of PHP and PHPUnit.
    - Cons:
        - Complex setup.
    - Howto:
        - Split your unit tests into two or more testsuites that take approximately the same time to run. The example below is for two test suites that are named ci-1 and ci-2.
        - Ensure that shell's job control is enabled or execute `set -m` in the console.
        - Execute `TEST_TOKEN=1 Vendor/bin/phpunit --testsuite ci-1 &> /tmp/ci-1.out & TEST_TOKEN=2 Vendor/bin/phpunit --testsuite ci-2 & fg` or similar command. This sets `TEST_TOKEN` environment variable, starts the first test suite in the background process and writes its output to a file in tmp folder, starts the second test suite and brings it output to the foreground. This way two test suites are run in parallel. Run the slowest test suite the last.
        - Execute `cat /tmp/ci-1.out` to print the results of the first test suite to the console.
        - Execute `grep "OK" /tmp/ci-1.out` or similar command to check that the first test suite successfully finished.
2. By using paratest library.

    - Pros:
        - Simple setup.
    - Cons:
        - Dependency to third party library.
        - Paratest is actively supported only for the latest PHP version therefore not all projects can use it.
    - Howto:
        - Install paratest and follow their instructions - .

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

3

Last Release

1645d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ebb49f7218c6a5e34f840d066b8820cc054b6b7f43a7b2edbde9464f3df8289?d=identicon)[bancer](/maintainers/bancer)

---

Top Contributors

[![bancer](https://avatars.githubusercontent.com/u/3830106?v=4)](https://github.com/bancer "bancer (3 commits)")

---

Tags

paratestphpphpunit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bancer-paratest-databases-factory/health.svg)

```
[![Health](https://phpackages.com/badges/bancer-paratest-databases-factory/health.svg)](https://phpackages.com/packages/bancer-paratest-databases-factory)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M677](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M753](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.0k](/packages/orchestra-testbench)

PHPackages © 2026

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