Data fixture before transaction attribute

The data fixture before transaction attribute is an extension of Data Fixture attribute that applies fixtures before the transaction and reverts applied fixtures after the transaction. With disabled DB isolation, this attribute is identical to the Data Fixture attribute

Format

#[
    DataFixtureBeforeTransaction(string $type, array $data = [], string $count = 1, string $scope = 'default', ?string $as = null)
]

Parameters

Example

In the following example, the fixtures supplied to the DataFixtureBeforeTransaction attribute are applied before the transaction, whereas fixtures supplied to the DataFixture attribute are applied within the transaction.

class CategoryTest extends TestCase
{
    #[
        DataFixtureBeforeTransaction(ScheduleMode::class, ['indexer' => 'catalog_category_product']),
        DataFixtureBeforeTransaction(ScheduleMode::class, ['indexer' => 'catalog_product_category']),
        DataFixture(Category::class, as: 'category'),
        DataFixture(Product::class, ['category_ids' => ['$category.id$']], 'product1'),
        DataFixture(Product::class, ['category_ids' => ['$category.id$']], 'product2'),
    ]
    public function testUpdateProductsPositionsWithIndexerOnSchedule(): void
    {

    }
}