Skip to content

Commit

Permalink
Automatically assign the fixtureHelper to each fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jkniest committed Jun 3, 2024
1 parent e2213e2 commit 61f8976
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

abstract class Fixture
{
protected readonly FixtureHelper $helper;

Check failure on line 9 in src/Fixture.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, stable)

Class Basecom\FixturePlugin\Fixture has an uninitialized readonly property $helper. Assign it in the constructor.

abstract public function load(): void;

/** @return string[] */
Expand All @@ -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;

Check failure on line 35 in src/Fixture.php

View workflow job for this annotation

GitHub Actions / Psalm (8.3, lowest)

InaccessibleProperty

src/Fixture.php:35:9: InaccessibleProperty: Basecom\FixturePlugin\Fixture::$helper is marked readonly (see https://psalm.dev/054)

Check failure on line 35 in src/Fixture.php

View workflow job for this annotation

GitHub Actions / Psalm (8.3, stable)

InaccessibleProperty

src/Fixture.php:35:9: InaccessibleProperty: Basecom\FixturePlugin\Fixture::$helper is marked readonly (see https://psalm.dev/054)

Check failure on line 35 in src/Fixture.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, stable)

Readonly property Basecom\FixturePlugin\Fixture::$helper is assigned outside of the constructor.
}
}
6 changes: 5 additions & 1 deletion src/FixtureLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class FixtureLoader
/**
* @param \Traversable<Fixture> $fixtures
*/
public function __construct(\Traversable $fixtures)
public function __construct(
\Traversable $fixtures,
private readonly FixtureHelper $helper,
)
{
$this->fixtures = iterator_to_array($fixtures);
}
Expand Down Expand Up @@ -177,6 +180,7 @@ private function runFixtures(FixtureOption $option, array $fixtures, ?SymfonySty
continue;
}

$fixture->setHelper($this->helper);
$fixture->load();
}
}
Expand Down

0 comments on commit 61f8976

Please sign in to comment.