Download the PHP package dknx01/data-fixtures-phpunit without Composer
On this page you can find all versions of the php package dknx01/data-fixtures-phpunit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dknx01/data-fixtures-phpunit
More information about dknx01/data-fixtures-phpunit
Files in dknx01/data-fixtures-phpunit
Package data-fixtures-phpunit
Short Description Symfony Bundle to use Doctrine data fixtures in PHPUnit tests.
License MIT
Informations about the package data-fixtures-phpunit
Data Fixture For PHPUnit Bundle
This is a Symfony Bundle to use Symfony DoctrineFixturesBundle in PHPUnit test directly.
Requirements
- Symfony DoctrineFixturesBundle
- PHPUnit
- (optional, but recommended) Faker
Install
- Create a config file (see Minimal Configuration)
- run
composer require --dev dknx01/data-fixtures-phpunit
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
Ensure you have the following file:
localeandproviders` are optional and only needed if you want to change the default behavior.
Minimal Configuration
The minimal setup would look like: `
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:
Writing a fixture
Each fixture must implement the Doctrine\Common\DataFixtures\FixtureInterface;.
Example:
As you can see the fixture can have constructor arguments for individual data in different tests.
Data Fixture on method level
Data fixtures can be used on class level (see above) and on method level.
Dependent Fixtures
Fixtures can depend on other fixtures. You can use the way Doctrine data fixtures is suggesting, or you can use an attribute.
Faker
As you can see it is possible to use PHPFaker inside a fixture class.
If you implement the FakerAware interface a Faker instance is automatically injected into the data fixture.
Limitations
- A fixture class can only be used once for a test, regardless of whether the DataFixture is defined on a class basis or a method basis
- This is invalid and will only execute on fixture, mostly the latest defined one
All versions of data-fixtures-phpunit with dependencies
doctrine/doctrine-fixtures-bundle Version ^4.3
symfony/framework-bundle Version 7.4.*||8.*