Skip to content

Respect strict/non-strict MySQL modes #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/wp-tests-phpunit-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@ const fs = require( 'fs' );
const path = require( 'path' );

const expectedErrors = [
'Tests_Comment_WpComment::test_get_instance_should_succeed_for_float_that_is_equal_to_post_id',
'Tests_Cron_getCronArray::test_get_cron_array_output_validation with data set "null"',
'Tests_DB_Charset::test_strip_invalid_text',
'Tests_DB::test_db_reconnect',
'Tests_DB::test_get_col_info',
'Tests_DB::test_process_fields_value_too_long_for_field with data set "invalid chars"',
'Tests_DB::test_process_fields_value_too_long_for_field with data set "too long"',
'Tests_DB::test_process_fields',
'Tests_DB::test_set_allowed_incompatible_sql_mode',
'Tests_DB::test_set_incompatible_sql_mode',
'Tests_DB::test_set_sql_mode',
'Tests_Post_wpPost::test_get_instance_should_succeed_for_float_that_is_equal_to_post_id',
'Tests_Post::test_stick_post_with_unexpected_sticky_posts_option with data set "null"',
];

const expectedFailures = [
Expand Down
32 changes: 3 additions & 29 deletions tests/WP_SQLite_Driver_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,13 @@ public static function setUpBeforeClass(): void {

// Before each test, we create a new database
public function setUp(): void {
global $blog_tables;
$queries = explode( ';', $blog_tables );

$this->sqlite = new PDO( 'sqlite::memory:' );
$this->engine = new WP_SQLite_Driver(
array(
'connection' => $this->sqlite,
'database' => 'wp',
)
);

$translator = $this->engine;

try {
$translator->begin_transaction();
foreach ( $queries as $query ) {
$query = trim( $query );
if ( empty( $query ) ) {
continue;
}

$translator->execute_sqlite_query( $query );
}
$translator->commit();
} catch ( PDOException $err ) {
$err_data =
$err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$err_code = $err_data[1];
$translator->rollback();
$message = sprintf(
'Error occurred while creating tables or indexes...<br />Query was: %s<br />',
var_export( $query, true )
);
$message .= sprintf( 'Error message is: %s', $err_data[2] );
wp_die( $message, 'Database Error!' );
}
}

public function testCountTables() {
Expand Down Expand Up @@ -480,6 +451,9 @@ private function assertTableEmpty( $table_name, $empty_var ) {
}

public function testTruncateTable() {
$this->assertQuery(
'CREATE TABLE wp_comments ( comment_author TEXT, comment_content TEXT )'
);

$this->assertQuery(
"INSERT INTO wp_comments ( comment_author, comment_content ) VALUES ( 'PhpUnit', 'Testing' )"
Expand Down
Loading