PHPackages                             dknx01/data-fixtures-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. dknx01/data-fixtures-phpunit

ActiveSymfony-bundle[Testing &amp; Quality](/categories/testing)

dknx01/data-fixtures-phpunit
============================

Symfony Bundle to use Doctrine data fixtures in PHPUnit tests.

0.1.3(2mo ago)03↓92.3%MITPHPPHP &gt;=8.3

Since Feb 23Pushed 2mo agoCompare

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

READMEChangelog (1)Dependencies (34)Versions (7)Used By (0)

Data Fixture For PHPUnit Bundle
===============================

[](#data-fixture-for-phpunit-bundle)

This is a Symfony Bundle to use [Symfony DoctrineFixturesBundle](https://symfony.com/bundles/DoctrineFixturesBundle/current/index.html) in PHPUnit test directly.

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

[](#requirements)

- [Symfony DoctrineFixturesBundle](https://symfony.com/bundles/DoctrineFixturesBundle/current/index.html)
- [PHPUnit](https://phpunit.de/index.html)
- (optional, but recommended) [Faker](https://fakerphp.org)

Install
-------

[](#install)

1. Create a config file (see [Minimal Configuration](#minimal-configuration))
2. run `composer require --dev dknx01/data-fixtures-phpunit`

Usage
-----

[](#usage)

If you want to use data fixtures in you tests you can do it in multiple ways. You can write a method to fill data in the database. or you can use a fixture and reuse it in multiple tests.

### Configuration

[](#configuration)

Ensure you have the following file:

```
# config/packages/data_fixtures_php_unit.yaml
data_fixtures_php_unit:
  faker:
    locale: 'de_DE' # optional - defaults to en_EN
    providers:
      - 'App\Tests\Faker\Bundeslaender' # optional - defaults to empty array
```

`locale` and `providers` are optional and only needed if you want to change the default behavior.

### Minimal Configuration

[](#minimal-configuration)

The minimal setup would look like:

```
# config/packages/data_fixtures_php_unit.yaml
data_fixtures_php_unit:
  faker:
```

### Fixtures registration

[](#fixtures-registration)

You should have all your Fixture classes registered as a services - at leat inside the test container.

All Fixtures that are in the namespace `App\Tests\Fixtures\` and inside the folder `'%kernel.project_dir%/tests/Fixtures'` are automatically registered.

Example registration:

```
when@test:
  services:
    _defaults:
      autowire: true
      autoconfigure: true
      public: true
    App\Tests\Fixtures\:
      resource: '%kernel.project_dir%/tests/Fixtures'
```

### Writing a fixture

[](#writing-a-fixture)

Each fixture must implement the `Doctrine\Common\DataFixtures\FixtureInterface;`. Example:

```
