Opened 8 years ago
Closed 8 years ago
#37046 closed defect (bug) (fixed)
Unit test initial setup fails if plugins added tables with foreign key constraints
Reported by: | javorszky | Owned by: | pento |
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | |
Focuses: | Cc: |
Description
When setting up a new test run, the script would drop all tables and recreate them from scratch. See here: https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/install.php?marks=43-45#L43
Relevant code copied:
foreach ( $wpdb->tables() as $table => $prefixed_table ) { $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); }
If there's a foreign key constraint on a table that has not been dropped yet that references one that's being dropped, MySQL (and MariaDB) will return an error about the foreign key constraint failing, and won't actually drop the table.
This can lead to dirty state for the next test.
Attachments (1)
Change History (5)
#2
@
8 years ago
- Owner set to pento
- Status changed from new to reviewing
This looks good to me, @pento thoughts?
Note: See
TracTickets for help on using
tickets.
Use case: testing a plugin that makes use of the WP testing library.
When the plugin's install script runs (either on init or hooked into activation), it creates a new table, for example:
where
$collate
isNext time I want to run the tests, the
posts
table will not have been deleted. This only works iftablename
comes later in alphabetical order thanposts
in this context.Patch incoming.