PHPackages                             metamodels/phpunit-contao-database - 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. metamodels/phpunit-contao-database

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

metamodels/phpunit-contao-database
==================================

MetaModels phpunit contao database classes

1.0.1(9y ago)210.3k3LGPL-3.0+PHPPHP &gt;=5.4

Since Jul 22Pushed 9y ago5 watchersCompare

[ Source](https://github.com/MetaModels/phpunit-contao-database)[ Packagist](https://packagist.org/packages/metamodels/phpunit-contao-database)[ Docs](http://now.metamodel.me/)[ RSS](/packages/metamodels-phpunit-contao-database/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (3)

MetaModels database objects for phpunit
=======================================

[](#metamodels-database-objects-for-phpunit)

What you can expect here.
-------------------------

[](#what-you-can-expect-here)

This repository holds a small subset of classes that can be used to fake a Contao database connection.

To do so, you define the queries and their result sets.

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

[](#installation)

Add `"metamodels/phpunit-contao-database": "~1.0"` to your `composer.json` in the `require-dev` section and you are set.

How to use it.
--------------

[](#how-to-use-it)

In your unit test you simply replace the original Contao database classes by calling the following code (before the original Contao database classes get loaded via autoloading!). A good place might be the `setUp()`-method of your test case.

```
class MyTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Register the database.
     *
     * @return void
     */
    public function setUp()
    {
        \MetaModels\Test\Contao\Database::register();
    }
}
```

Using it in unit tests
----------------------

[](#using-it-in-unit-tests)

You should use dependency injection for proper unit testing, then you can use something like this:

```
$objectToTest = new ClassToTest();
$database     = \MetaModels\Test\Contao\Database::getNewTestInstance();

// Inject the database into the instance.
$objectToTest->setDatabase($database);

$database
    ->getQueryCollection()
    ->theQuery('SELECT * FROM test WHERE id=?')
    ->with(1)
    ->result()
        ->addRow(
            array(
              'id'     => 1,
              'tstamp' => 343094400,
              'title'  => 'test'
            ),
        );

// This method will call the above query internally and will receive the given result.
$result = $objectToTest->testMethod();

$this->assertEquals(1, $result->getId());
$this->assertEquals(343094400, $result->getModificationTime());
$this->assertEquals('test', $result->getTitle());
```

If you should be in the unfortunate position that you can not use dependency injection, as the underlying code is using `Database::getInstance()`, you are not out of luck. You can use the method `$database = \MetaModels\Test\Contao\Database::getNewTestInstance();` which will return the "default" database instance then.

However using this approach is not suggested as the instance will be shared over all unit tests.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3589d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3

1.0.1PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44649522?v=4)[xtra](/maintainers/xtra)[@xtra](https://github.com/xtra)

![](https://avatars.githubusercontent.com/u/10211934?v=4)[Chibineko](/maintainers/Chibineko)[@chibineko](https://github.com/chibineko)

---

Top Contributors

[![discordier](https://avatars.githubusercontent.com/u/940331?v=4)](https://github.com/discordier "discordier (10 commits)")

---

Tags

phpunitmetamodels

### Embed Badge

![Health badge](/badges/metamodels-phpunit-contao-database/health.svg)

```
[![Health](https://phpackages.com/badges/metamodels-phpunit-contao-database/health.svg)](https://phpackages.com/packages/metamodels-phpunit-contao-database)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78137.2M122](/packages/johnkary-phpunit-speedtrap)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

56426.3M456](/packages/dg-bypass-finals)[phpspec/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

19254.9M1.4k](/packages/phpspec-prophecy-phpunit)

PHPackages © 2026

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