PHPackages                             kununu/data-fixtures - 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. [Database &amp; ORM](/categories/database)
4. /
5. kununu/data-fixtures

ActiveLibrary[Database &amp; ORM](/categories/database)

kununu/data-fixtures
====================

Load data fixtures in your application for any storage

v15.0.0(3mo ago)774.0k↓47.1%1MITPHPPHP &gt;=8.4CI passing

Since Apr 17Pushed 2w ago12 watchersCompare

[ Source](https://github.com/kununu/data-fixtures)[ Packagist](https://packagist.org/packages/kununu/data-fixtures)[ RSS](/packages/kununu-data-fixtures/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (16)Versions (32)Used By (1)

kununu data-fixtures
====================

[](#kununu-data-fixtures)

At kununu we rely on data fixtures in our tests as well in our development and testing environments. A good definition of what fixtures are is the one from the documentation of [DoctrineFixturesBundle](https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html) in which the design and implementation of this package was heavily based on.

> Fixtures are used to load a “fake” set of data into a database that can then be used for testing or to help give you some interesting data while you’re developing your application.

### What is kununu/data-fixtures?

[](#what-is-kununudata-fixtures)

This package provides a simple way to manage and execute the loading of data fixtures for any storage mechanism.

Its design and implementation was heavily based on the [Doctrine data-fixtures](https://github.com/doctrine/data-fixtures) package.

If you are interested in why we created this package check out [Why kununu/data-fixtures?](docs/why-kununu-data-fixtures.md).

### Fixtures types

[](#fixtures-types)

Currently, this package supports the following types of fixtures:

- *[Doctrine DBAL Connection Fixtures](docs/FixtureTypes/doctrine-dbal-connection-fixtures.md)* which relies on [Doctrine DBAL](https://github.com/doctrine/dbal) by using the [Connection](https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php) implementation
- *[Cache Pool Fixtures](docs/FixtureTypes/cache-pool-fixtures.md)* which relies on implementations of the [PSR-6](https://github.com/php-fig/cache) standard
- *[DynamoDB Fixtures](docs/FixtureTypes/dynamodb.md)* which relies on the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) DynamoDB client
- *[Elasticsearch Fixtures](docs/FixtureTypes/elasticsearch.md)* which relies on the [Elasticsearch-PHP client](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)
- *[OpenSearch Fixtures](docs/FixtureTypes/opensearch.md)* which relies on the [OpenSearch PHP client](https://opensearch.org/docs/latest/clients/php/)
- *[Symfony Http Client Fixtures](docs/FixtureTypes/symfony-http-client.md)* which relies on the [Symfony Http Client](https://github.com/symfony/http-client) and [Symfony Http Foundation](https://github.com/symfony/http-foundation).

Also check [Directory Loader](docs/FixtureTypes/directory-loader.md) to check how to load fixtures from files in a directory.

If you are interested in knowing more about the concepts of the package, or you need to create a new fixture type check out [How to create a new Fixture Type](docs/how-to-create-new-fixture-type.md).

---

Install
-------

[](#install)

#### 1. Add kununu/data-fixtures to your project

[](#1-add-kununudata-fixtures-to-your-project)

Before installing this package be aware:

- **You own the fixtures you load**
- **This package should not be used in production mode!**

```
composer require --dev kununu/data-fixtures
```

#### 2. Enable any fixture type

[](#2-enable-any-fixture-type)

In order to enable the fixture types that you are interested, check out their documentation:

- [Doctrine DBAL Connection Fixtures](docs/FixtureTypes/doctrine-dbal-connection-fixtures.md)
- [Cache Pool Fixtures](docs/FixtureTypes/cache-pool-fixtures.md)
- [DynamoDB Fixtures](docs/FixtureTypes/dynamodb.md)
- [Elasticsearch Fixtures](docs/FixtureTypes/elasticsearch.md)
- [OpenSearch Fixtures](docs/FixtureTypes/opensearch.md)
- [Symfony Http Client Fixtures](docs/FixtureTypes/symfony-http-client.md)

---

Append Fixtures
---------------

[](#append-fixtures)

By default, when loading fixtures the data storage is purged. If you want to change this behavior and instead append the fixtures you can pass *false* as second argument to any executor.

```
// By default, the data storage is purged
$executor->execute($loader->getFixtures());
// If you want you can `append` the fixtures instead of purging the database
$executor->execute($loader->getFixtures(), true);
```

---

Load Fixtures
-------------

[](#load-fixtures)

In order to load fixtures the default [Loader](src/Loader/Loader.php) provides a couple of options:

1. `loadFromDirectory(string $dir)`
2. `loadFromFile(string $fileName)`
3. `loadFromClassName(string $className)`
4. `addFixture(FixtureInterface $fixture)`

```
