Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deletion helper to reduce complexity #64

Merged
merged 20 commits into from
Jun 14, 2024
Merged

Conversation

jkniest
Copy link
Member

@jkniest jkniest commented Jun 3, 2024

Before (v2):

class ClearCategoriesFixture extends Fixture
{
    public function __construct(
        private EntityRepository $categoryRepository,
    ) {
    }

    public function load(FixtureBag $bag): void
    {
        $this->removeAllCategories();
    }

    private function removeAllCategories(): void
    {
        $this->deleteCategoryForLevel(4);
        $this->deleteCategoryForLevel(3);
        $this->deleteCategoryForLevel(2);
    }

    private function deleteCategoryForLevel(int $level): void
    {
        $criteria = (new Criteria())
            ->addFilter(new EqualsFilter('level', $level));

        $ids = $this->categoryRepository
            ->searchIds($criteria, Context::createDefaultContext())
            ->getData();

        $this->categoryRepository->delete(
            array_values($ids),
            Context::createDefaultContext()
        );
    }

After (v3):

class ClearDockwareDataFixture extends Fixture
{
    public function load(): void
    {
        $this->removeAllCategories();
    }

    private function removeAllCategories(): void
    {
        $this->deleteCategoryForLevel(4);
        $this->deleteCategoryForLevel(3);
        $this->deleteCategoryForLevel(2);
    }

    private function deleteCategoryForLevel(int $level): void
    {
        $this->helper->Database()->deleteEntities(
            'category',
            (new Criteria())->addFilter(new EqualsFilter('level', $level)),
        );
    }

Optimizations:

  • Helper is now included in every fixture
  • No need to manually fetch the repository anymore

@jkniest jkniest changed the base branch from main to feature/update-test-trait June 3, 2024 14:33
@jkniest jkniest self-assigned this Jun 3, 2024
It can´t be readonly, because you use a setter and you will set the helper on other classes
src/Fixture.php Outdated Show resolved Hide resolved
Base automatically changed from feature/update-test-trait to main June 14, 2024 06:51
dependabot bot and others added 4 commits June 14, 2024 09:23
Updates the requirements on [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) to permit the latest version.
- [Release notes](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases)
- [Changelog](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/CHANGELOG.md)
- [Commits](PHP-CS-Fixer/PHP-CS-Fixer@v3.57.2...v3.58.1)

---
updated-dependencies:
- dependency-name: friendsofphp/php-cs-fixer
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Dont run vendor fixtures by default, add flag to run vendor fixtures

* Trailing slashes!

* Change docs formats

* Use first class callable syntax

* Refactor FixtureTrait

* Enable phpstan rule: checkMissingIterableValueType

* Enable rule checkGenericClassInNonGenericObjectType in psalm

* Disable error warnings if generics arent provided, since they were added in SW 6.5.something
@jkniest jkniest merged commit faead55 into main Jun 14, 2024
11 checks passed
@jkniest jkniest deleted the feature/delete-helper branch June 14, 2024 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants