Skip to content

feat(test-writing): forbid DB mutation in migration setUp/tearDown#111

Merged
Martin Bens (SpiGAndromeda) merged 1 commit into
mainfrom
feat/test-writing-migration-setup-teardown-rule
May 13, 2026
Merged

feat(test-writing): forbid DB mutation in migration setUp/tearDown#111
Martin Bens (SpiGAndromeda) merged 1 commit into
mainfrom
feat/test-writing-migration-setup-teardown-rule

Conversation

@SpiGAndromeda
Copy link
Copy Markdown
Collaborator

No description provided.

Migration test classes always contain testGetCreationTimestamp (MIGRATION-008), which runs the same setUp and tearDown but never touches the database. Mutations placed in those hooks therefore run around a test that doesn't need them and leave non-transactional schema or per-row state for sibling test classes. shopware/shopware PR #16799 fixed this pattern across 19 files. MIGRATION-009 catches it on the way in.

The rule flags ALTER, CREATE, DROP, INSERT, UPDATE, DELETE, TRUNCATE, REPLACE plus $conn->insert/update/delete and schema-manager mutations inside setUp or tearDown, including inside try/catch wrappers. Connection acquisition, PHP-side ID generation, and read-only fetches stay permitted. Two canonical fixes work: a private helper called from the test method, or a try/finally block inside the test.

MIGRATION-005 was broadened in the same change. Its "in setUp/tearDown" qualifier is gone now that MIGRATION-009 owns where cleanup lives. The one-statement-per-try and catch-Throwable teaching points still apply at any cleanup site. The Schema-Remove section of the migration test template no longer restores via tearDown. Restore now lives inside testUpdateDestructive in a try/finally block.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

@SpiGAndromeda Martin Bens (SpiGAndromeda) merged commit 70ac8cb into main May 13, 2026
12 checks passed
@SpiGAndromeda Martin Bens (SpiGAndromeda) deleted the feat/test-writing-migration-setup-teardown-rule branch May 13, 2026 11:48
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