PHPackages                             imjoehaines/flowder - 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. imjoehaines/flowder

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

imjoehaines/flowder
===================

A simple and extensible fixture loader for PHP 7.3+, supporting SQLite and MySQL

v2.0.0(6y ago)6629.5k2[1 PRs](https://github.com/imjoehaines/flowder/pulls)2UnlicensePHPPHP ^7.3CI failing

Since Apr 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/imjoehaines/flowder)[ Packagist](https://packagist.org/packages/imjoehaines/flowder)[ Docs](https://github.com/imjoehaines/flowder)[ RSS](/packages/imjoehaines-flowder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (2)

Flowder [![Latest Stable Version](https://camo.githubusercontent.com/4dee243e7051b12841cd3f3a806853436f3b5555417802a2d496cdd4b5c72ee6/68747470733a2f2f706f7365722e707567782e6f72672f696d6a6f656861696e65732f666c6f776465722f762f737461626c65)](https://packagist.org/packages/imjoehaines/flowder)
==================================================================================================================================================================================================================================================================================================

[](#flowder-)

Flowder is a (really) simple fixture loader for PHP 7.3+, supporting SQLite and MySQL.

*Using Flowder in PHP 7.2 or below? Try [version 1](https://packagist.org/packages/imjoehaines/flowder#v1.0.0) instead!*

**NB:** If you're looking to use Flowder in a project, you probably want to use an exisiting framework integration:

- [Flowder PHPUnit](https://github.com/imjoehaines/flowder-phpunit) — A Flowder test listener for PHPUnit
- [Flowdception](https://github.com/imjoehaines/flowdception) — A Flowder Extension for Codception

Basic Concepts
--------------

[](#basic-concepts)

Flowder is built with three basic building blocks; [Loaders](#loaders), [Truncators](#truncators) and [Persisters](#persisters).

A Loader is responsible for taking a thing to load (such as a file or directory) and converting it into an array of data that can be persisted.

A Truncator is responsible for ensuring all the database tables where data will be persisted are empty before persisting the data.

A Persister is responsible for taking the data provided by a Loader and inserting it into the database.

These three concepts are represented by the following interfaces:

- [`Imjoehaines\Flowder\Loader\LoaderInterface`](src/Loader/LoaderInterface.php)
- [`Imjoehaines\Flowder\Truncator\TruncatorInterface`](src/Truncator/TruncatorInterface.php)
- [`Imjoehaines\Flowder\Persister\PersisterInterface`](src/Persister/PersisterInterface.php)

Building your own Loaders, Truncators and Persisters is as easy as creating a class that implements ones of these interfaces.

Usage
-----

[](#usage)

Loading fixtures with Flowder takes a few lines of code — it just requires a Loader, Truncator and Persister.

For example, to load a single PHP file into a SQLite in-memory database, the following file could be used

```
$db = new PDO('sqlite::memory:');

$flowder = new Imjoehaines\Flowder\Flowder(
    new Imjoehaines\Flowder\Loader\PhpFileLoader(),
    new Imjoehaines\Flowder\Truncator\SqliteTruncator($db),
    new Imjoehaines\Flowder\Persister\SqlitePersister($db)
);

$flowder->loadFixtures('test_data.php');
```

Provided Classes
----------------

[](#provided-classes)

#### Flowder

[](#flowder)

`Flowder` is the main class you will be using. It is responsible for orchestrating the loading, truncating and persisting processes.

As seen in the example above, it is constructed with three arguments — an instance of `LoaderInterface`, an instance of `TruncatorInterface` and an instance of `PersisterInterface`.

After construction, call `loadFixtures` and pass it a thing to load in order to persist the data. For example, using the `PhpFileLoader` you would pass `loadFixtures` the path to a PHP file.

### Loaders

[](#loaders)

Flowder comes bundled with three Loaders:

#### PhpFileLoader

[](#phpfileloader)

This Loader takes a PHP file name, `require`s it and uses a returned array of data as the data to be persisted. The file name itself is used as the table name (ignoring the file extension).

For example, given the following `example_table.php` file

```
return [
    [
        'column1' => 1,
        'column2' => 2,
    ],
    [
        'column1' => 4,
        'column2' => 5,
    ],
];
```

Then when loaded with the `PhpFileLoader`, it would return the following PHP array

```
[
    'example_table' => [
        [
            'column1' => 1,
            'column2' => 2,
        ],
        [
            'column1' => 4,
            'column2' => 5,
        ],
    ],
]
```

#### DirectoryLoader

[](#directoryloader)

The `DirectoryLoader` is a decorator around another Loader instance that will run the Loader's `load` method for each file in the directory provided to `DirectoryLoader::load`.

For example, the following code will load all files in `/some/directory` using the `PhpFileLoader`

```
$loader = new DirectoryLoader(
    new PhpFileLoader()
);

$data = $loader->load('/some/directory');
```

#### CachingLoader

[](#cachingloader)

The `CachingLoader` is another decorator that caches the result of it's `load` method so that repeated calls to load the same thing will return the same result as it did on the first call to `load`.

Extending the above example, we can use the following code to load all files in `/some/directory` using the `PhpFileLoader`, but only actually hit the disk on the first time through the `for` loop. All other iterations will simply return the cached value

```
$loader = new CachingLoader(
    new DirectoryLoader(
        new PhpFileLoader()
    )
);

for ($i = 0; $i < 100; $i++) {
    $data = $loader->load('/some/directory');
}
```

It is usually a good idea to use the CachingLoader whenever you are loading the same resource more than once as it can dramatically speed up fixture loading.

#### Additional Loaders

[](#additional-loaders)

For loading file formats other than PHP, take a look at the JSON or YAML loaders:

- [JSON Loader](https://github.com/imjoehaines/flowder-json-loader)
- [YAML Loader](https://github.com/imjoehaines/flowder-yaml-loader)

### Truncators

[](#truncators)

Flowder comes with two Truncator classes:

#### MySqlTruncator

[](#mysqltruncator)

This Truncator takes a table name and runs a MySQL `TRUNCATE TABLE` query on it. It will disable foreign key checks before the truncate and enable them afterwards, to ensure ordering of truncation does not matter. It is your responsibility to make sure this does not leave your database in an inconsistent state after all of your fixtures run.

#### SqliteTruncator

[](#sqlitetruncator)

This Truncator takes a table name and runs a `DELETE FROM` query on it. Like the `MySqlTruncator`, it will disable foreign key checks before the truncate and enable them afterwards.

### Persisters

[](#persisters)

#### MySqlPersister

[](#mysqlpersister)

The `MySqlPersister` takes a table name and array of data and converts it into a single `INSERT` query. Like the `MySqlTruncator` it will disable foreign key checks before the insert and enable them afterwards to ensure the ordering of inserts does not matter. It is your responsibility to make sure this does not leave your database in an inconsistent state after all of your fixtures run.

#### SqlitePersister

[](#sqlitepersister)

The `SqlitePersister` is functionally identical to the `MySqlPersister`, but inserts data a row at a time inside a transaction instead of building a single `INSERT` query. This is to get around SQLite's [`SQLITE_MAX_VARIABLE_NUMBER`](https://www.sqlite.org/lang_expr.html#varparam) limitation.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.2% 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 ~1016 days

Total

2

Last Release

2290d ago

Major Versions

v1.0.0 → v2.0.02020-02-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/df2f67ab383494b3813cced6ae7005077e5b04c1d807ef76514ef3cffc600e82?d=identicon)[imjoehaines](/maintainers/imjoehaines)

---

Top Contributors

[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (170 commits)")[![imjoehaines](https://avatars.githubusercontent.com/u/282732?v=4)](https://github.com/imjoehaines "imjoehaines (127 commits)")

---

Tags

fixture-loadingfixturesflowdermysqlphpsqlitetestingtestingfixturesmysqlsqlitefixture-loading

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[liip/test-fixtures-bundle

This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications

1798.3M42](/packages/liip-test-fixtures-bundle)[chriskite/phactory

A Database Factory for PHP Unit Tests

140216.9k8](/packages/chriskite-phactory)[vectorface/mysqlite

Select MySQL compatibility functions for PDO's SQLite driver

3639.5k1](/packages/vectorface-mysqlite)[derptest/phpmachinist

Testing object factory for PHP

3636.9k1](/packages/derptest-phpmachinist)[phpmachinist/phpmachinist

Testing object factory for PHP

3630.7k](/packages/phpmachinist-phpmachinist)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2227.8k](/packages/guanguans-laravel-soar)

PHPackages © 2026

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