Skip to content

Commit d7c3309

Browse files
authored
Fix deprecation warnings, report them in tests (#280)
It turns out that `E_DEPRECATED` was excluded in the test bootstrap. When enabling it, I found a few small issues, plus fixed this one: ``` PHP Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in .../sqlite-database-integration/wp-includes/sqlite-ast/class-wp-sqlite-driver.php on line 2868 ``` This deprecation warning occurs on PHP >= 8.4 when a SQL variable with a `null` value is read.
1 parent b142e59 commit d7c3309

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6276,6 +6276,33 @@ public function testUserVariables(): void {
62766276
$this->assertEquals( 3, $result[0]->{'@my_var'} );
62776277
}
62786278

6279+
public function testVariableBackupAndRestoreForDumps(): void {
6280+
// Set and backup variables.
6281+
$this->assertQuery( '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' );
6282+
$this->assertQuery( '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' );
6283+
$this->assertQuery( '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' );
6284+
$this->assertQuery( '/*!50503 SET NAMES utf8mb4 */;' );
6285+
$this->assertQuery( '/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;' );
6286+
$this->assertQuery( "/*!40103 SET TIME_ZONE='+00:00' */;" );
6287+
$this->assertQuery( '/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;' );
6288+
$this->assertQuery( '/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;' );
6289+
$this->assertQuery( "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;" );
6290+
$this->assertQuery( '/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;' );
6291+
$this->assertQuery( '/*!40101 SET @saved_cs_client = @@character_set_client */; ' );
6292+
$this->assertQuery( '/*!50503 SET character_set_client = utf8mb4 */;' );
6293+
6294+
// Restore variables.
6295+
$this->assertQuery( '/*!40101 SET character_set_client = @saved_cs_client */;' );
6296+
$this->assertQuery( '/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;' );
6297+
$this->assertQuery( '/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;' );
6298+
$this->assertQuery( '/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;' );
6299+
$this->assertQuery( '/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;' );
6300+
$this->assertQuery( '/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;' );
6301+
$this->assertQuery( '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' );
6302+
$this->assertQuery( '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;' );
6303+
$this->assertQuery( '/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;' );
6304+
}
6305+
62796306
public function testLockingStatements(): void {
62806307
$this->assertQuery( 'CREATE TABLE t (id INT)' );
62816308

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-reconstructor.php';
2424

2525
// Configure the test environment.
26-
error_reporting( E_ALL & ~E_DEPRECATED );
26+
error_reporting( E_ALL );
2727
define( 'FQDB', ':memory:' );
2828
define( 'FQDBDIR', __DIR__ . '/../testdb' );
2929

tests/mysql/WP_MySQL_Server_Suite_Lexer_Tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function test_tokenize_mysql_test_suite(): void {
2121
}
2222

2323
try {
24-
while ( ( $record = fgetcsv( $handle ) ) !== false ) {
24+
while ( ( $record = fgetcsv( $handle, null, ',', '"', '\\' ) ) !== false ) {
2525
$query = $record[0];
2626
$lexer = new WP_MySQL_Lexer( $query );
2727
$tokens = $lexer->remaining_tokens();

tests/mysql/WP_MySQL_Server_Suite_Parser_Tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function data_parse_mysql_test_suite(): Generator {
7575
try {
7676
$data = array();
7777
$batch = 1;
78-
while ( ( $record = fgetcsv( $handle ) ) !== false ) {
78+
while ( ( $record = fgetcsv( $handle, null, ',', '"', '\\' ) ) !== false ) {
7979
$data[] = $record;
8080
if ( count( $data ) === 1000 ) {
8181
yield "batch-$batch" => array( $data );

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ private function execute_update_statement( WP_Parser_Node $node ): void {
15981598
* UPDATE t, information_schema.columns c SET t.column = c.column ...
15991599
*/
16001600
foreach ( $table_alias_map as $alias => $data ) {
1601-
if ( 'information_schema' === strtolower( $data['database'] ) ) {
1601+
if ( 'information_schema' === strtolower( $data['database'] ?? '' ) ) {
16021602
throw $this->new_access_denied_to_information_schema_exception();
16031603
}
16041604
}
@@ -2281,7 +2281,7 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
22812281
'flags' => array( 'not_null' ),
22822282
'table' => '',
22832283
'name' => 'Create Table',
2284-
'len' => strlen( $sql ),
2284+
'len' => strlen( $sql ?? '' ),
22852285
'precision' => 31,
22862286
),
22872287
);
@@ -2925,7 +2925,7 @@ private function execute_set_system_variable_statement(
29252925
* SET updatable_views_with_limit = OFF; ERROR 1231 (42000)
29262926
* SET updatable_views_with_limit = false; SELECT @@updatable_views_with_limit; -> NO
29272927
*/
2928-
$lowercase_value = strtolower( $value );
2928+
$lowercase_value = null === $value ? null : strtolower( $value );
29292929
if ( 'on' === $lowercase_value || 'off' === $lowercase_value ) {
29302930
$value = 'on' === $lowercase_value ? 1 : 0;
29312931
}

0 commit comments

Comments
 (0)