PHPackages                             vkr/fixture-loader-bundle - 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. vkr/fixture-loader-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

vkr/fixture-loader-bundle
=========================

A bundle for Symfony2/3 that adds loading mechanisms for MySQL Doctrine fixtures

1.0.1(9y ago)022MITPHPPHP &gt;=5.6

Since Apr 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/wladislavk/FixtureLoaderBundle)[ Packagist](https://packagist.org/packages/vkr/fixture-loader-bundle)[ Docs](https://github.com/wladislavk/FixtureLoaderBundle)[ RSS](/packages/vkr-fixture-loader-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

Overview
========

[](#overview)

This bundle simplifies loading of fixtures for applications that use Doctrine Fixtures and MySQL. It introduces sensible defaults and provides a couple of console commands that replace `doctrine:fixtures:load` and provides an opportunity to write your own commands and rulesets. It also deals with an old and well-known bug that concerns truncating the DB that contains foreign keys.

Please note that this bundle contains some non-ANSI-compatible MySQL code and therefore cannot be used with other DB drivers supported by Doctrine DBAL.

Configuration
=============

[](#configuration)

This bundle accepts two configuration parameters, both of which are optional and located under `vkr_fixture_loader` key.

`fixture_directory` sets the path relative to Symfony root directory for the parent directory to where your fixture directories are located. For example, if you have `InitialData` and `TestData` directories as children to `/symfony/path/fixtures`, then this setting should be set to `/fixtures`. The default value is `/src/AppBundle/DataFixtures/ORM`.

`fixture_type_manager` setting needs to be used if you create your own type manager. It should be equal to service alias as set in `services.yml`. The default value is `vkr_fixture_loader.fixture_type_manager`.

Composition
===========

[](#composition)

FixturesLoader
--------------

[](#fixturesloader)

At the heart of this bundle lies a service called `FixturesLoader`. Its only public method `loadFixtures()` accepts three arguments. The first argument corresponds to the directory name of the fixture subset relative to `fixture_directory` setting. The second argument is a callable that is responsible for displaying the logging information to the console. This callable can be set in the `execute()` method of your command class and should use `OutputInterface` variable of Symfony Console component. The third argument is a boolean that purges the database (not the table!) if false or keeps the existing data if true.

Unlike the default Doctrine Fixtures load command, this service is opinionated in the following manner:

1. If the third argument is false, the data is always purged, not deleted, that allows client coders to rely upon auto-incremented columns in fixtures.
2. Foreign key checks are always disabled while purging to suppress error messages in younger versions of MySQL.

If the directory specified as the first argument is empty or does not exist, no errors will be thrown and, given that the third argument is false, the data will be purged anyway.

FixtureTypeManager
------------------

[](#fixturetypemanager)

This simple class defines the ruleset for various console fixture loaders. The default version of this class defines three public methods.

`setLoggingFunction()` accepts a callable as its argument and passes it on to `FixturesLoader`. This method must be called before any other method.

`loadInitialData()` handles `vkr:fixtures:initial` command, it loads fixtures from `InitialData` directory and purges the DB if `--purge` option is set.

`restoreTestDB()` handles `vkr:fixtures:test` command. It does the following:

1. purges the DB
2. loads fixtures from `InitialData` directory if they exist
3. loads fixtures from `TestData directory`.

This class can be extended to include your own commands and rulesets.

Console commands
----------------

[](#console-commands)

Two commands are shipped with this bundle.

`vkr:fixtures:initial` is designed to set static data that is needed for the application to work and is unlikely to change in the future, such as list of supported languages. It loads fixtures from `InitialData` directory and it will purge the DB if called with `--purge`option (meaning that it will not purge anything by default). It is important to understand that if this option is not set, target tables will not be purged, which can lead to unexpected behavior. It is recommended to truncate the data from target tables manually in your fixture classes.

`vkr:fixtures:test` is designed for restoring the test database data for functional tests. It purges the database, then tries to load `InitialData` fixtures (that allows to avoid the overhead of running `vkr:fixtures:initial`), then loads fixtures from `TestData` directory. In order to be foolproof, this command will error out if used without `--env=test` option. It allows to define `parameters_test.yml` file with its own connection data that will be used for purgeable test DB while keeping the main DB safe. If one test environment is not enough for you, you can create additional environments that contain the word `test` in their names and use this command in this manner: `vkr:fixtures:test --env=test2`.

Both commands can work with non-default entity managers by providing `--em` option.

Customization
=============

[](#customization)

Custom type managers
--------------------

[](#custom-type-managers)

If you want to define your own fixture-loading commands or override the behavior of built-in commands, you can define your own classes that extend `FixtureTypeManager`and add public methods or override existing methods. It is recommended to call `$this->loadFixtures()` from all new methods.

Custom commands
---------------

[](#custom-commands)

You can add your own console commands that will use `FixtureTypeManager` and `FixturesLoader`. The easiest way to do this is to copy one of the built-in commands and modify it. It is recommended to include these lines in your `execute()`method:

```
$managerServiceName = $this->getContainer()->getParameter(Constants::FIXTURE_MANAGER_PARAM);
/** @var FixtureTypeManager $fixtureTypeManager */
$fixtureTypeManager = $this->getContainer()->get($managerServiceName);
if (!$fixtureTypeManager instanceof FixtureTypeManager) {
    throw new FixtureLoaderException('Fixture type manager service must extend ' . FixtureTypeManager::class);
}
...
$fixtureTypeManager->setLoggingFunction($myLoggingFunction);
$fixtureTypeManager->myPublicMethod();
return null;

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

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

Total

2

Last Release

3316d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79f5fa971e7fda7a6180c1bdfca4f819a43b7681ec4e04c66b184a082fb5a20f?d=identicon)[wladislavk](/maintainers/wladislavk)

---

Top Contributors

[![wladislavk](https://avatars.githubusercontent.com/u/11371476?v=4)](https://github.com/wladislavk "wladislavk (2 commits)")

---

Tags

fixturesmysqldoctrineSymfony2symfony3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vkr-fixture-loader-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/vkr-fixture-loader-bundle/health.svg)](https://phpackages.com/packages/vkr-fixture-loader-bundle)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[data-dog/audit-bundle

Audit bundle for symfony2 and doctrine orm, logs any database change

141901.7k1](/packages/data-dog-audit-bundle)[webonaute/doctrine-fixtures-generator-bundle

Generate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.

67184.1k](/packages/webonaute-doctrine-fixtures-generator-bundle)[h4cc/alice-fixtures-bundle

Symfony2 Bundle for loading fixture data with the Alice library.

76314.2k7](/packages/h4cc-alice-fixtures-bundle)[petkopara/crud-generator-bundle

Symfony3 bundle for CRUD generation with pagination, filtering, sorting, page size, bulk delete and bootstrap3 markup. This Generator supports Doctrine association mapping.

7257.9k](/packages/petkopara-crud-generator-bundle)

PHPackages © 2026

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