Tests: Fix explode() error for old DB versions on PHP 8.1+.

On MySQL/MariaDB 5.5, the default value for `sql_mode` was a blank string. By itself this is not a problem. However, `$wpdb->get_var()` returns `null` when a variable has an empty value.

One test method currently passes the result of `$wpdb->get_var( 'SELECT @@SESSION.sql_mode;' )` to `explode()` in order to reset the database to the pre-test method state. This causes an error when running PHP 8.1+, which deprecated the ability to pass `null` as a parameter of `explode()`.

This edge case was undiscovered because these versions are not currently included in the automated testing matrix.

See #62280.

git-svn-id: https://develop.svn.wordpress.org/trunk@59583 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2025-01-07 15:40:19 +00:00
parent 4a9a928dbc
commit d0e1e903fb

View File

@ -296,7 +296,7 @@ class Tests_DB extends WP_UnitTestCase {
$check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
$this->assertSameSets( $new_modes, explode( ',', $check_new_modes ) );
$wpdb->set_sql_mode( explode( ',', $current_modes ) );
$wpdb->set_sql_mode( empty( $current_modes ) ? array() : explode( ',', $current_modes ) );
}
/**