The unit tests transform all CREATE TABLE
and DROP TABLE
queries to CREATE TEMPORARY TABLE
and DROP TEMPORARY TALBE
, respectively. So in your tearDown
the query will attempt to drop temporary tables with those names, but not the actual tables. To fix this, add this before your DROP
queries:
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
You may also need to add this before your CREATE TABLE
queries:
remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
The WP_UnitTestCase::_create_temporary_tables()
function is the one that filters the queries to make tables temporary. It is added in the setUp()
, and removed in the tearDown()
.
Update:
The _create_temporary_tables()
function is now hooked to the 'query'
filter, instead of 'dbdelta_create_queries'
. See changeset 27041. So now to remove it you would do:
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
Related Posts:
- Post meta vs separate database tables
- Is it mandatory to use $wpdb->prefix in custom tables
- Default table collation on plugin activation?
- Unit tests – Dealing with dependencies
- Using a database view = evil incarnate?
- How to write testable classes in WordPress
- PHPUnit testing WordPress Plugin
- Getting wrong relationship value in $args in wp_Query?
- WordPress and multithreading
- Implement phpunit testing on a plugin
- Not sure the best way to save custom plugin data
- The ideal place for storing persistent PHP objects
- What is the added “complexity” of custom tables?
- How is the data stored in the database?
- Formatting of curly brackets array from WP database to get more readable output
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Unit testing wordpress plugins with plugin options
- Install and load additional plugins when running unit tests
- Unit Testing a Plugin functionality with cron
- Hello dolly type plugin that allows people to add their own
- Sample — test — data for large WordPress install
- Is there any reason only 1 (my) IP would be added to this table using $wpdn->insert?
- Why is WP_Mock not used instead of WP_UnitTestCase for writing unit tests by most plugins?
- How to store data for posts/pages built with drag-n-drop builder?
- DataBase connection problem with PHPUnit and WordPress
- Is there a naming convention for database tables created by a plugin?
- Activation hook not creating table
- Is the usage of ON DELETE CASCADE wrong or not allowed on wordpress?
- Saving data from block editor to the database
- What for the tables ending with the meta used in database of wordpress?
- Creating table with plugin is not working
- dbDelta() Error – Incorrect index name ” for query ALTER TABLE
- Get a custom table to an array
- Update/insert only a column of database table
- How to Create database table when Plugin installed/activated, and delete database when Plugin deleted
- I’m designing a plugin to create database indexes. Suggestions?
- WordPress database error for query INSERT INTO
- How to connect to AWS RDS external database (not for the core WordPress db)
- How should I store a log for my plugin
- How to create database table, add data, update and delete using wpdb via plugins?
- Using WPDB to output raw XML fails because of wp-blog-header.php
- Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?
- Strange issue saving custom field data for a WooCommerce order
- Form doesnt save to database
- Updating Woocommerce Settings API when WordPress Settings API saved and vise versa
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- Unit testing a plugin with a theme dependency
- Plugin Development for registered users
- Optimising a big WordPress site
- wpdb->prepare and mysql UPDATE – how is it done?
- dbDelta SQL Query Not Working
- What is the best way to store a few fields?
- Plugin: database creation
- How to query custom db table?
- Delete data from database using row action
- Show dynamic list of products from custom api of another database under same host
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Make Database query only when option is updated
- Can we intercept user_login and user_pass from a wp_login_form?
- How best to handle database version dependence (from $wp_db_version)
- WP: Search and replace in DB programmatically
- Using AND and bracket grouping in SQL not working
- Two different wordpress sites – same server and IP address. Gaining Access to database 1 of 2
- Plugin Development: Storing and Manipulating Data That Fits JSON in Database
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- How do I debug an error that a plugin is causing?
- Update plugin settings option_name for big plugin update
- $wpdb->update Issue
- dbdelta failing with error: “WordPress database error Table ‘wp_2_myPlugin’ already exists
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Error code when migrate
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- PHPUnit Testing and woocommerce Constant
- Unit Testing action hook
- WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta()
- Use admin-post to submit form data to external database
- Save in my custom admin page and redirect to the saved object
- Relational / Associate tables using native WordPress functionality
- How to store in the database directly the translation?
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- pull data from wordpress database
- Ajax not working to insert, query and result data
- Why Worpdress doesn’t create table in database?
- Form and database, plugin development
- Associating special meaning with user id 0
- What method should I use to store my plugin data (multi level menus with options on each item)
- How to add additional field in a table row after creating a table?
- WordPress plugin tables become corrupt
- Post data in wp-admin to external database
- Running one-off cron jobs when WP_DISABLE_CRON is true: can I hit /wp-cron.php?
- PHPUnit Ajax Serialization of ‘Closure’ is not allowed
- PHPUnit Testing Installation Issue
- How to create a database table in WordPress using PHP
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- WordPress database error: [Table ‘bitnami_wordpress.questions’ doesn’t exist]
- Making a user platform reachable by a qr code on a pin-back-button [closed]
- multiple record insert creating many duplicate records