Download the PHP package dknx01/data-fixtures without Composer
On this page you can find all versions of the php package dknx01/data-fixtures. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dknx01/data-fixtures
More information about dknx01/data-fixtures
Files in dknx01/data-fixtures
Package data-fixtures
Short Description A PHP package for data fixtures with plain PDO connection.
License MIT
Informations about the package data-fixtures
DKNX01/Data-fixtures
A PHP package for data fixtures with plain PDO connection.
Requirements
- ext-pdo for PDO connections
- (optional, but recommended) Faker
Install
- 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.
With an existing PDO connection
If you already have a PDO connection you can use it directly.
Create a new PDO connection
Configuration:
The Configuration object has the following parameters:
| Parameter | Description |
|---|---|
| pdo | An existing PDO connection that will be used |
| dsn | The dsn of the PDO connection |
| user | Databases user, if needed |
| password | Databases users password, if needed |
| options | PDO options that will be used for the connection |
Load and execute fixtures
Your class should use the DataFixtureTrait.
If you do not want to use the trait, you can load and execute the fixtures this way:
loadFixtures(int $stackPosition = 1)
This option should be used to define at which stack position the fixtures should be loaded from. Mostly it will be "1" which means directly from the method/class the "loadFixtures" method is called from. If you have more inherited classes, you can change the number.
Writing a fixture
Each fixture must implement the Dknx01\DataFixtures\Contract\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.
Ordered Fixtures
Fixtures can have an order at which position they should load in the fixture loading process.
If a position is added multiple times, the early will move one step ahead of the latest ones.
Example:
This attribute will overwrite the DependFixture attribute!
In this example the FooFixture is loaded at position 0 which means at the beginning of all fixtures.
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.
Examples
You can see some examples in the directory examples or you can run the script
All versions of data-fixtures with dependencies
ext-pdo Version *