Closed alexstandiford closed 3 years ago
Not sure if this is the best way, but I do this at the start of my unit tests and it works well for me:
foreach ( restrict_content_pro()->components as $component ) {
$table = $component->get_interface( 'table' );
if ( $table instanceof \RCP\Database\Table ) {
if ( $table->exists() ) {
$table->uninstall();
}
$table->install();
}
}
This is basically what in doing, too. Do you see the error I described above?
How about truncate()
or delete_all()
? :zoidberg:
IF EXISTS
to the drop table syntax?IF EXISTS
would not generate this error. 😇
Probably not.
Transactions could always happen anywhere outside of Berlin, so there is no way to know if it's wrapped in one or why. In the case that you've found, it's explicitly making sure tables are temporary.
How about truncate() or delete_all()? :zoidberg:
I suppose my reasoning for drop
and create
is that I wanted the table to completely reset instead of simply removing all of the data.
Judging by what @ashleyfae said above, it seems like this is probably specific to my use case, and is probably indicative of something amiss with my specific setup.
If nobody else is experiencing this, we can probably close this.
I've never gotten the error before. I can double check again later but pretty confident I haven't seen it.
No movement in a few months, so I'm closing just to keep open issues to a minimum.
Please reopen anytime if needed, and thank you everyone for the discussion 🥳
If you try to drop a table using
Table::drop
inside of a WordPress unit test case, you will receive an error something like this:WordPress database error: [Unknown table 'wordpress_test.wptests_table_name']
DROP TEMPORARY TABLE wptests_table_name
It's entirely possible this is just a bug in what I've built, but wanted to see if others are experiencing this.
When I add
IF EXISTS
to the end of the drop statement, these errors go away. I'm not certain this is the best way to handle this, however, since in my context I usually drop a table to reset the table back to the default settings. So I suppose my questions are:IF EXISTS
to the drop table syntax?I did a small amount of digging, and found this: https://wordpress.stackexchange.com/a/220308/105777