PHPackages                             hrodic/php-integration-testing - 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. hrodic/php-integration-testing

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

hrodic/php-integration-testing
==============================

Integration testing library for PHP

v1.0(5y ago)52511MITPHPPHP ^7.3CI failing

Since Apr 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/hrodic/php-integration-testing)[ Packagist](https://packagist.org/packages/hrodic/php-integration-testing)[ RSS](/packages/hrodic-php-integration-testing/feed)WikiDiscussions master Synced 6d ago

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

PHP Integration Testing
=======================

[](#php-integration-testing)

Integration testing library in PHP for databases and other common infrastructure related tests.

[![Build Status](https://camo.githubusercontent.com/3df1e14f51122cf13622ea34cd695f74976e40d01b47c46ac8a994d7cb2eedad/68747470733a2f2f7472617669732d63692e636f6d2f68726f6469632f7068702d696e746567726174696f6e2d74657374696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/hrodic/php-integration-testing)[![Maintainability](https://camo.githubusercontent.com/6ebf26d21683fe746762518e5c8a5a36c62d153b2300c0fe7a1c86529f960478/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64666664623432613034643964623161396238392f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/hrodic/php-integration-testing/maintainability)[![Test Coverage](https://camo.githubusercontent.com/3433d61cdaef220c78a41e0b18b40de47d96ba0f6881b1810b72055dd792935b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64666664623432613034643964623161396238392f746573745f636f766572616765)](https://codeclimate.com/github/hrodic/php-integration-testing/test_coverage)

It is developed as a set of extensions for PHPUnit that hooks on different events and executes your fixtures.

Currently you can run custom fixtures on the following PHPUnit hooks:

- BeforeFirstTest
- BeforeTest
- AfterTest
- AfterLastTest

Road map
--------

[](#road-map)

- WIP: AMQP specific test fixtures with WithBeforeTestFixtureName and WithAfterTestFixtureName

Requirements
------------

[](#requirements)

[PHPUnit](https://phpunit.readthedocs.io/en/9.1)

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

[](#installation)

Via composer

```
composer require --dev hrodic/php-integration-testing

```

Configuration
-------------

[](#configuration)

On PHPUnit configuration XML file you must specify the extension with its configuration.

You are able to specify the configuration filename that you will be using. Defaults to .integration-testing.json

```

            .integration-testing.json

```

You also check phpunit-integration.xml.dist example

If you need help with PHPUnit extensions, please refer to the [Official Documentation](https://phpunit.readthedocs.io/en/9.1/configuration.html#the-extensions-element)

### PDO Fixtures

[](#pdo-fixtures)

If you need to test the integration of MySQL or MariaDB, use the PDO driver extension.

It requires configuration parameters that can be found in the json config file.

The most important parameters are DSN, username and password of your database + some fixture path definitions.

Example:

```
"pdo": {
    "dsn": "mysql:host=localhost:3306;dbname=test;charset=utf8",
    "user": "test",
    "password": "test",
    "fixtures": {
      "beforeFirstTest": {
        "path": "tests/fixtures/before-first-test",
        "extension": "sql"
      },
      "beforeTest": {
        "path": "tests/fixtures/before-test",
        "extension": "sql"
      },
      "afterTest": {
        "path": "tests/fixtures/after-test"
      },
      "afterLastTest": {
        "path": "tests/fixtures/after-last-test"
      }
    }
},

```

### AMQP fixtures

[](#amqp-fixtures)

You can also try out AMQP (tested on RabbitMQ) fixtures and operations.

Configure your connectivity and the hook operations using the configuration file.

Notes:

- Hook definitions are optional, so just configure the ones you need.
- You can only publish messages on `beforeFirstTest` and on `beforeTest`.
- You can purge queues in all four hooks.
- file extension of message bodies to publish defaults to `json`
- use `routing_key` if you have your exchange configured as `direct`. You can define it as empty string if `fanout`

```
"amqp": {
    "host": "localhost",
    "port": 5672,
    "user": "test",
    "password": "test",
    "vhost": "/",
    "fixtures": {
      "beforeFirstTest": {
        "purgeQueues": [
          "before-first-test-queue"
        ],
        "publishMessages": [
          {
            "exchange": "test-exchange",
            "queue": "before-first-test-queue",
            "routing_key": "before-first-test",
            "path": "tests/fixtures/before-first-test",
            "extension": "json"
          }
        ]
      },
      "beforeTest": {
        "purgeQueues": [
          "before-test-queue"
        ],
        "publishMessages": [
          {
            "exchange": "test-exchange",
            "queue": "before-test-queue",
            "routing_key": "before-test",
            "path": "tests/fixtures/before-test"
          }
        ]
      },
      "afterTest": {
        "purgeQueues": [
          "before-test-queue"
        ]
      },
      "afterLastTest": {
        "purgeQueues": []
      }
    }
  }

```

Fixture creation
----------------

[](#fixture-creation)

A PDO fixture is just an SQL file.

All the fixtures located in a specific hook category will be executed in order and inside a transaction.

How you create the SQL and the integrity of the database in each stage is up to you. The library does not force you to follow any convention although is common to setup fixtures at the beginning and clean your mess after each test.

You can create, insert, delete or whatever you configure your user to do. Remember, your testing database must be isolated from any real database!

All four fixture hook types could be placed in the directory that you prefer.

For BeforeTest and AfterTest hooks, which occur in every specific test, you can also provide specific fixtures to be executed just after the generic Before and After fixtures by implementing the interfaces WithBeforeTestFixtureName and/or WithAfterTestFixtureName.

```
final class YourIntegrationTest extends TestCase implements WithBeforeTestFixtureName, WithAfterTestFixtureName
{
    private const FIXTURE_NAME = 'pdo-integration-test';

    public static function getAfterTestFixtureName(): string
    {
        return self::FIXTURE_NAME;
    }

    public static function getBeforeTestFixtureName(): string
    {
        return self::FIXTURE_NAME;
    }

    public function testYourRepositoryHere(): void
    {
        // arrange
        // act
        // assert against real database (your fixtures are already there!)
    }
}

```

The Extension will check if the methods are defined, and use them to locate subdirectories inside the main BEFORE\_TEST\_PDO\_FIXTURES\_PATH and AFTER\_TEST\_PDO\_FIXTURES\_PATH directories.

### Execution flow

[](#execution-flow)

If you take a look onto the tests/fixtures folder, you will see an example on how you can organize your fixtures. You can have multiple SQL files and the extension will read and execute them in order.

```
├── after-last-test                     # AFTER_LAST_TEST_PDO_FIXTURES_PATH, executed once, at the end
│   └── 01.sql
├── after-test                          # AFTER_TEST_PDO_FIXTURES_PATH, executed after each test
│   ├── 01.sql
│   └── pdo-integration-test            # executed after each test inside the class that defines this fixture name
│       └── 01.sql
├── before-first-test                   # BEFORE_FIRST_TEST_PDO_FIXTURES_PATH, executed once, at the beginning
│   └── 01.sql
└── before-test                         # BEFORE_TEST_PDO_FIXTURES_PATH, executed before each test
    ├── 01.sql
    └── pdo-integration-test            # executed before each test inside the class that defines this fixture name
        └── 01.sql

```

Troubleshooting
---------------

[](#troubleshooting)

Integration testing requires some infrastructure to be in place.

This library assumes (you can check docker-compose.yml file for inspiration) that you have an accessible database or other infrastructure already in place and the database is created.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

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

Total

5

Last Release

2163d ago

### Community

Maintainers

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

---

Top Contributors

[![hrodic](https://avatars.githubusercontent.com/u/1694951?v=4)](https://github.com/hrodic "hrodic (37 commits)")

---

Tags

integrationintegration-testingmariadbphpphp7phpunitphpunit-extensionphpunit-testsphpunit9sqltestingphptestintegration

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/hrodic-php-integration-testing/health.svg)

```
[![Health](https://phpackages.com/badges/hrodic-php-integration-testing/health.svg)](https://phpackages.com/packages/hrodic-php-integration-testing)
```

###  Alternatives

[letsdrink/ouzo-goodies

Utility classes, test assertions and mocking framework extracted from Ouzo framework.

132617.9k7](/packages/letsdrink-ouzo-goodies)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)[yegor256/phprack

Light framework for automation of integration tests

254.7k](/packages/yegor256-phprack)[hot/phpunit-runner

The lib allows to watch phpunit tests

3066.9k4](/packages/hot-phpunit-runner)[derptest/phpmachinist

Testing object factory for PHP

3636.9k1](/packages/derptest-phpmachinist)[genesis/behat-sql-extension

SQL/PDO extension that facilitates fixture data creation on the fly for Behat

1179.9k3](/packages/genesis-behat-sql-extension)

PHPackages © 2026

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