diff --git a/CHANGELOG.md b/CHANGELOG.md index fd50aef..bbc3246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support for Shopware 6.6 - Added `--dry` option to all fixture load commands - This option will prevent the fixtures from being executed but still prints all fixtures it would execute +- Added new DatabaseUtils with a few helpful methods: + - `deleteEntities` takes an entity name and criteria and deletes all entities which match the criteria ### Changed - Changed argument type on `SalesChannelUtils::getTax()` from `int` to `float` @@ -19,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `FixtureTrait::runSpecificFixtures` is an alias to run specific fixtures with optionally dependencies - `FixtureTrait::runSingleFixture` (before `FixtureTrait::runSingleFixtureWithDependencies`) with dependencies can now be configured as the second parameter - `FixtureTrait::runFixtureGroup` is a new function to execute whole fixture groups with optionally dependencies +- Each fixture now has direct access to the FixtureHelper using `$this->helper` + - **Breaking** If you have the helper (or any other helper) previously assigned to `$this->helper` it will either fail or override the FixturePlugin helper ### Removed - Dropped support for PHP 8.1 diff --git a/src/Fixture.php b/src/Fixture.php index da7e1a3..0341081 100644 --- a/src/Fixture.php +++ b/src/Fixture.php @@ -6,6 +6,8 @@ abstract class Fixture { + protected readonly FixtureHelper $helper; + abstract public function load(): void; /** @return string[] */ @@ -24,4 +26,12 @@ public function groups(): array { return []; } + + /** + * @internal This method should only be called from the FixtureLoader. + */ + public final function setHelper(FixtureHelper $helper): void + { + $this->helper = $helper; + } } diff --git a/src/FixtureLoader.php b/src/FixtureLoader.php index 1b3cf08..967478e 100644 --- a/src/FixtureLoader.php +++ b/src/FixtureLoader.php @@ -14,7 +14,10 @@ class FixtureLoader /** * @param \Traversable $fixtures */ - public function __construct(\Traversable $fixtures) + public function __construct( + \Traversable $fixtures, + private readonly FixtureHelper $helper, + ) { $this->fixtures = iterator_to_array($fixtures); } @@ -177,6 +180,7 @@ private function runFixtures(FixtureOption $option, array $fixtures, ?SymfonySty continue; } + $fixture->setHelper($this->helper); $fixture->load(); } }