From 9dcdfddc15c6b544a7fcfe76248a2a166365c49e Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Wed, 5 May 2021 11:50:43 +0200 Subject: [PATCH] Fix table creation detection in DataRegeneratorTest --- .../ProductAttributesLookup/DataRegeneratorTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/php/src/Internal/ProductAttributesLookup/DataRegeneratorTest.php b/tests/php/src/Internal/ProductAttributesLookup/DataRegeneratorTest.php index bde4569878b..a40f97c42a2 100644 --- a/tests/php/src/Internal/ProductAttributesLookup/DataRegeneratorTest.php +++ b/tests/php/src/Internal/ProductAttributesLookup/DataRegeneratorTest.php @@ -94,9 +94,11 @@ class DataRegeneratorTest extends \WC_Unit_Test_Case { $this->sut->initiate_regeneration(); - $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $this->lookup_table_name ) ); - - $this->assertEquals( $this->lookup_table_name, $wpdb->get_var( $query ) ); + // Try to insert a row to verify that the table exists. + // We can't use the regular table existence detection mechanisms because PHPUnit creates all tables as temporary. + $wpdb->query( 'INSERT INTO ' . $this->lookup_table_name . " VALUES (1, 1, 'taxonomy', 1, 1, 1 )" ); + $value = $wpdb->get_var( 'SELECT product_id FROM ' . $this->lookup_table_name . ' LIMIT 1' ); + $this->assertEquals( 1, $value ); // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared }