Skip to content

feat: add doctrine:fixtures:down for revertible fixtures - #6

Merged
brianvarskonst merged 3 commits into
mainfrom
feat/fixtures-down
Nov 15, 2026
Merged

brianvarskonst merged 3 commits into
mainfrom
feat/fixtures-down

Conversation

@brianvarskonst

Copy link
Copy Markdown
Member

What

Part 3 of 3 of migration-style fixtures (status → up → down). Ships as v1.1.0 after merge.

  • RevertibleFixtureInterface::down(ObjectManager) marks a fixture as revertible.
  • doctrine:fixtures:down [fixtures...] [--all] [--group] [--em]:
    • reverts the last batch by default, the given fixture classes, the executed fixtures of --group, or --all;
    • adds executed fixtures that depend (transitively) on a target and reverts in reverse dependency order (dependents first);
    • refuses the whole run, reverting nothing, if the plan contains a fixture without down() or an unavailable class;
    • shows the plan and asks for confirmation; --no-interaction proceeds like doctrine:migrations:migrate -n;
    • one transaction per fixture with the removal of its record; references from executed fixtures are restored, so down() can use getReference().
  • Reference restoring moved into AbstractFixturesCommand (shared by up and down).
  • ProductionGuardPass hides down in production.
  • README section and CHANGELOG for 1.1.0.

Verification

composer qa passes locally on PHP 8.5 (18 tests, 147 assertions): last batch only, explicit fixture with dependents first, irreversible fixture blocks the run, declined confirmation, not-executed fixture rejected, production container without down.

Fixtures implementing RevertibleFixtureInterface::down() can be reverted:
the last batch by default, given fixtures or --all. Executed dependents are
reverted first, each in its own transaction with its record. A plan with an
irreversible or unavailable fixture reverts nothing. The command asks for
confirmation, proceeds with --no-interaction and is hidden in production.
Under WordPress, mysqli runs with MYSQLI_REPORT_OFF and DBAL turns a
missing table into a TypeError instead of TableNotFoundException. Check
the table through schema introspection, bypassing the asset filters.
@brianvarskonst

Copy link
Copy Markdown
Member Author

End-to-end check in a real WordPress (wordpress-astro-sympress worktree, disposable copy of the MariaDB 11.8 database, mysqli driver, WP_DEBUG on):

  • up across two batches; a fixture in batch 2 resolved a reference created in batch 1.
  • status, and doctrine:schema:update --dump-sql stays clean (tracking table hidden).
  • down of a batch containing fixtures without down() was refused and changed nothing.
  • down <fixture> reverted the dependent fixture first, then the target.
  • A fixture failing after flush() was rolled back (savepoint inside the outer transaction) and stayed pending; the fixture before it stayed executed.
  • WordPress tables untouched.

Found and fixed in 1a9b80d: WordPress sets mysqli_report(MYSQLI_REPORT_OFF), so DBAL's mysqli driver turns a missing table into a TypeError instead of TableNotFoundException. The storage now checks the table through schema introspection (bypassing asset filters) instead of catching the exception.

@brianvarskonst
brianvarskonst merged commit d48b2e2 into main Nov 15, 2026
3 checks passed
@brianvarskonst
brianvarskonst deleted the feat/fixtures-down branch November 15, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant