PHPackages                             hotel-quickly/nette-phpunit - 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. hotel-quickly/nette-phpunit

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

hotel-quickly/nette-phpunit
===========================

Nette + PHPunit + Multiple dbs + fixtures

0.2.1(9y ago)02.2k1MITPHP

Since Jan 13Pushed 8y ago24 watchersCompare

[ Source](https://github.com/HotelQuickly/NettePhpunit)[ Packagist](https://packagist.org/packages/hotel-quickly/nette-phpunit)[ RSS](/packages/hotel-quickly-nette-phpunit/feed)WikiDiscussions master Synced 2mo ago

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

Nette PHPUnit [![Build Status](https://camo.githubusercontent.com/4496a00fd09c99bc4e273045623e43fde043ea4e40ff13bf46f8940a6942fd38/68747470733a2f2f7472617669732d63692e6f72672f486f74656c517569636b6c792f4e65747465506870756e69742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/HotelQuickly/NettePhpunit)
========================================================================================================================================================================================================================================================================================================================

[](#nette-phpunit-)

- Support multiple database connections
- Support multiple fixtures formats loading (for each connection)

Getting started
---------------

[](#getting-started)

#### Installation

[](#installation)

Run the following commands to install this package

```
composer require --dev hotel-quickly/nette-phpunit
```

#### Usage

[](#usage)

In order to use Database test case, you must extend your base class from `HQ\Test\AbstractDbTestCase` and implement these 3 methods

1. `getContainer` - This method will return `Nette\Di\Container` instance.
2. `getConnections` - Return an array of `HQ\Test\Connection\AbstractConnection(connectionName, baseSchema, ...)` connections object.

- **connectionName** - A database connection name, which will be used as a prefix of fixture file.
- **baseSchema** - Database schema which includes `CREATE TABLE ...` sql statements.

3. `getBaseFixtureDir` - Return a base directory for searching base fixture file (see

```
use HQ\Test\AbstractDbTestCase;
use HQ\Test\Connection\NetteConnection;

class YourBaseDbTestCase extends AbstractDbTestCase
{
    protected function getContainer()
    {
        return require dirname(__DIR__) . '/app/bootstrap.php';
    }

    protected function getConnections()
    {
        return [
            new NetteConnection('default', __DIR__ . '/../tests/skeleton.sql', $this->container->getService('database.default.context'))
        ];
    }

    public function getBaseFixtureDir()
    {
        return __DIR__;
    }
}
```

Working with fixtures
---------------------

[](#working-with-fixtures)

#### Loading fixtures

[](#loading-fixtures)

By default, fixtures will be automatically loaded from 3 places, in the following orders

1. `base fixtures`
2. `class fixtures`
3. `instance fixtures`

##### 1. base fixtures

[](#1-base-fixtures)

This is a primary fixtures that will be loaded for all test cases (think of it as initial data for the whole apps)

```
test
  +- YourBaseDbTestCase.php
  +- -fixtures.{yaml, json, php} e.g. default-fixtures.json
```

##### 2. class fixtures

[](#2-class-fixtures)

This will be loaded each time test case was invoked.

```
test
  +- User
    +- UserTest.php
    +- -fixtures.{yaml, json, php} e.g. default-fixtures.json
```

##### 3. instance fixtures

[](#3-instance-fixtures)

This is pretty much the same as `class fixtures`, except that we define the fixture inside `TestCase` itself (so only `php array` is supported.

```
class MyTest extends MyBaseDbTestCase
{
    public function getFixtures()
    {
        return [
            '' => [
                ...
            ]
        ]
    }
}
```

\####Fixture formats + structure This library currently supports 3 fixture formats e.g. `json`, `yaml` and `php`. All formats has the same fixture structure i.e.

```
[
  "": [
     [
        "": "",
        "": ""
     ],
     ...
   ]
]

```

**`json`** example

```
{
    "user": [
        {"username": "john"},
        {"username": "jane"}
    ]
}
```

**`yaml`** example

```
user:
  -
    username: john
  -
    username: jane
```

**`php`** example - **NOTE** - Don't forget to put `return` statement

```
return [
    'user' => [
        ['username' => 'john'],
        ['username' => 'jane'],
    ]
]
```

Improving testing speed
-----------------------

[](#improving-testing-speed)

Due to the overhead of creating database schema at the beginning of the tests (only once). This might slow down your test suites speed. You can avoid this problem by exporting `UNITTEST_CREATE_SCHEMA=false` env and then run unit test as usual. This will make it skips database schema create overhead.

Common problems
---------------

[](#common-problems)

- InvalidArgumentException: There is already a table named account with different table definition.

This error indicates that your fixtures for same dataset (`table` e.g. `user`) has different column structure. For example, you have `default-fixtures.yaml` that contains `user` table and it has the following fields

```
user:
  -
    username: john
```

But somewhere in other fixtures, you have same user table with different fields e.g.

```
user:
  -
    email: john
```

This will cause the above error. To fix this, just make sure you define the *same fields* on each fixtures.

- ErrorException: ini\_set(): Cannot change zlib.output\_compression - headers already sent

This happens when Nette has php ini `zlib.output_compression` enabled in the container. Removing this config during testing will fix this error

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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 ~70 days

Total

4

Last Release

3563d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e3f8dea4056382add16f44eed862beebcba723c5fcd08d0408d854ecf1f2a01?d=identicon)[HotelQuickly](/maintainers/HotelQuickly)

---

Top Contributors

[![rezigned](https://avatars.githubusercontent.com/u/562145?v=4)](https://github.com/rezigned "rezigned (9 commits)")[![1josefnevoral](https://avatars.githubusercontent.com/u/1532335?v=4)](https://github.com/1josefnevoral "1josefnevoral (2 commits)")[![bamboorat](https://avatars.githubusercontent.com/u/6091331?v=4)](https://github.com/bamboorat "bamboorat (1 commits)")

### Embed Badge

![Health badge](/badges/hotel-quickly-nette-phpunit/health.svg)

```
[![Health](https://phpackages.com/badges/hotel-quickly-nette-phpunit/health.svg)](https://phpackages.com/packages/hotel-quickly-nette-phpunit)
```

###  Alternatives

[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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