Skip to content

fix(tia): select only the tests that touch a changed migration's tables - #1879

Open
talaridisTh wants to merge 1 commit into
pestphp:5.xfrom
talaridisTh:tia-precise-migration-selection
Open

fix(tia): select only the tests that touch a changed migration's tables#1879
talaridisTh wants to merge 1 commit into
pestphp:5.xfrom
talaridisTh:tia-precise-migration-selection

Conversation

@talaridisTh

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description:

On a Laravel suite whose base TestCase uses RefreshDatabase, changing any migration makes --tia select the entire suite, even though the graph already knows exactly which tables each test file queried.

The cause is Tia::augmentDatabaseTestTables: every test whose class uses RefreshDatabase / DatabaseMigrations / DatabaseTransactions gets every table declared under database/migrations merged into its recorded table list, whether or not it recorded tables of its own. With the trait on the base class, that is every test, so Graph::applyMigrationChanges intersects the changed migration against a table list that contains everything, and a one-column migration on orders re-runs 13k tests. On the suite I measured, that is the difference between a few seconds and a full run on every migration.

This keeps the conservative behaviour only where it is needed:

  • A database test that recorded no table usage (nothing went through the query listener, so there is nothing to match) is still linked to every declared table.
  • A database test that did record tables keeps exactly those. A migration touching orders now selects the tests that queried orders, which is what the table tracking exists for.
  • Graph::applyMigrationChanges routes a parseable migration that matches no recorded test through the watch-pattern fallback, the same path an unparseable migration takes. Before, that case could only happen without RefreshDatabase; now it is reachable for every suite, and it must not silently select nothing.

The augmentation moves out of the plugin into Tia\DatabaseTestTables so it can be unit tested; the traversal of database/migrations is unchanged.

Tests: tests/Unit/Plugins/Tia/DatabaseTestTables.php covers the three shapes (tracked, untracked, no database), and Graph.php gains the no-match fallback and the no-match-no-pattern case. tests/Features/Tia (200) and tests/Unit/Plugins/Tia (174) pass, composer lint and composer test:type:check are clean.

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