PHPackages                             eloqunit/eloqunit - 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. eloqunit/eloqunit

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

eloqunit/eloqunit
=================

A dbunit-like tool for phpunit and eloquent

0.4(5y ago)34MITPHP

Since Nov 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/brettmc/eloqunit)[ Packagist](https://packagist.org/packages/eloqunit/eloqunit)[ Docs](https://github.com/brettmc/eloqunit)[ RSS](/packages/eloqunit-eloqunit/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

eloqunit
========

[](#eloqunit)

[![Latest Stable Version](https://camo.githubusercontent.com/0df775b0a3c71b6f0af01f132f55f19dea15fdd32acf42cec20d0a8b947c72c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6f71756e69742f656c6f71756e69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eloqunit/eloqunit)[![Build Status](https://camo.githubusercontent.com/b988fc8f625c79a798348d7d492c7813c5cf0912639433fd16edaf9b3fd2a1a9/68747470733a2f2f7472617669732d63692e636f6d2f62726574746d632f656c6f71756e69742e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/brettmc/eloqunit)[![Coverage Status](https://camo.githubusercontent.com/84b41d0f6bd16a965338e77db3f5429487d359dc2ea3df1e577f85f6017fac2f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62726574746d632f656c6f71756e69742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/brettmc/eloqunit?branch=master)

An eloquent-based database testing library for phpunit, inspired by dbunit.

This works well with Slim Framework (and possibly others) which allows you to create an application, then dispatch multiple requests to it. By using database transactions for each test, you do not need to "tear down" data from prior tests, nor deal with artifacts left over from failed tests.

Features
--------

[](#features)

- runs test cases inside a database transaction
- provides assertions
- provides a `seed` method to quickly populate database tables
- support for null/not null on assertions

Installation
------------

[](#installation)

Install via composer:

```
$ composer require eloqunit/eloqunit

```

Usage
-----

[](#usage)

Instead of extending `PHPUnit\Framework\TestCase`, have your tests extend `Eloqunit\TestCase`. You need to provide a `getDatabase()` method, which returns a `Illuminate\Database\Capsule\Manager`, assertions, seeding etc are executed against this database. This only works if the database is the same one as used in the the system under test (eg, they are shared through a DI container).

Methods
-------

[](#methods)

### `seed(string $table, array $data)`:

[](#seedstring-table-array-data)

Seed $table with rows contained in $data.

```
$this->seed('mytable', [
  ['id' => '1', 'name' => 'row.one', 'active' => true, 'foo' => null],
  ['2', 'row.two', false, 'bar'],
]);
```

### `seedTables(array $data)`:

[](#seedtablesarray-data)

Seed multiple tables. Array keys represent table names, and array values represent table rows.

```
$this->seedTables(
    'mytable' => [
        ['id' => 1, 'name' => 'row.one', 'active' => true],
        [2, 'row.two', true],
        [3, 'row.three', true],
    ],
    'myothertable' => [
        ['key' => 'foo', 'description' => 'description of foo'],
        ['bar', 'bar description'],
        ['baz', 'baz description'],
    ],
);
```

### `assertRowCount(int $expected, string $table, array $where, string $message)`:

[](#assertrowcountint-expected-string-table-array-where-string-message)

Assert that `$table` contains `$expected` number of rows. Optionally, filtered by $where.

```
$this->assertRowCount(1, 'mytable', ['active' => true, 'foo' => Eloqunit\Constraint::IsNull]);
$this->assertRowCount(1, 'mytable', ['active' => false, 'foo' => ELoqunit\Constraint::IsNotNull];
$this->assertRowCount(2, 'mytable');
```

### `assertRowExists(string $table, array $where, string $message)`

[](#assertrowexistsstring-table-array-where-string-message)

Assert that a row exists in $table. Optionally, filtered by $where.

```
$this->assertRowExists('mytable', ['id' => 1]);
$this->assertRowExists('mytable', ['foo' => Eloqunit\Constraint::IsNotNull]);
```

### `assertRowMatches(string $table, array $where, array $fields)`

[](#assertrowmatchesstring-table-array-where-array-fields)

Assert that the first row in $table which matches $where, contains fields matching $fields.

```
$this->assertRowMatches('mytable', ['id' => 1], ['name' => 'row.one', 'active' => true]);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~205 days

Total

5

Last Release

1920d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4978962?v=4)[Brett McBride](/maintainers/brettmc)[@brettmc](https://github.com/brettmc)

---

Top Contributors

[![brettmc](https://avatars.githubusercontent.com/u/4978962?v=4)](https://github.com/brettmc "brettmc (23 commits)")

---

Tags

eloquentphpunit-extensiontestingphpuniteloquent

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/eloqunit-eloqunit/health.svg)

```
[![Health](https://phpackages.com/badges/eloqunit-eloqunit/health.svg)](https://phpackages.com/packages/eloqunit-eloqunit)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M510](/packages/spatie-phpunit-snapshot-assertions)[phpunit/phpunit-selenium

Selenium Server integration for PHPUnit

59610.9M150](/packages/phpunit-phpunit-selenium)[yoast/phpunit-polyfills

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests

18338.5M841](/packages/yoast-phpunit-polyfills)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[matthiasnoback/symfony-config-test

Library for testing user classes related to the Symfony Config Component

1679.8M395](/packages/matthiasnoback-symfony-config-test)

PHPackages © 2026

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