Skip to content

Commit 791a7da

Browse files
committed
test: avoid custom savepoint fixture table
1 parent 852f068 commit 791a7da

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎tests/phpunit/WP_SQLite_Database_Integration_Savepoint_Test.php‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,38 @@ class WP_SQLite_Database_Integration_Savepoint_Test extends WP_UnitTestCase {
55
public function test_wpdb_update_inside_savepoint_does_not_open_nested_transaction() {
66
global $wpdb;
77

8-
$table_name = $wpdb->prefix . 'sqlite_savepoint_write_test';
9-
$wpdb->query( $wpdb->prepare( 'CREATE TABLE %i (id INT PRIMARY KEY, value INT)', $table_name ) );
8+
$option_name = 'sqlite_savepoint_write_test';
109
$wpdb->insert(
11-
$table_name,
10+
$wpdb->options,
1211
array(
13-
'id' => 1,
14-
'value' => 1,
12+
'option_name' => $option_name,
13+
'option_value' => '1',
14+
'autoload' => 'no',
1515
)
1616
);
1717

1818
try {
1919
$this->assertNotFalse( $wpdb->query( 'SAVEPOINT wpdb_update' ) );
2020

21-
$result = $wpdb->update( $table_name, array( 'value' => 2 ), array( 'id' => 1 ) );
21+
$result = $wpdb->update( $wpdb->options, array( 'option_value' => '2' ), array( 'option_name' => $option_name ) );
2222
$queries = array_column( $wpdb->get_driver()->get_last_sqlite_queries(), 'sql' );
2323

2424
$this->assertSame( 1, $result );
2525
$this->assertSame( 1, $wpdb->rows_affected );
2626
$this->assertSame( '', $wpdb->last_error );
2727
$this->assertNotContains( 'BEGIN IMMEDIATE', $queries );
2828
$this->assertNotFalse( $wpdb->query( 'RELEASE SAVEPOINT wpdb_update' ) );
29-
$this->assertSame( '2', $wpdb->get_var( $wpdb->prepare( 'SELECT value FROM %i WHERE id = 1', $table_name ) ) );
29+
$this->assertSame(
30+
'2',
31+
$wpdb->get_var(
32+
$wpdb->prepare( 'SELECT option_value FROM %i WHERE option_name = %s', $wpdb->options, $option_name )
33+
)
34+
);
3035
} finally {
3136
if ( $wpdb->get_driver()->inTransaction() ) {
3237
$wpdb->query( 'ROLLBACK' );
3338
}
34-
$wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table_name ) );
39+
$wpdb->delete( $wpdb->options, array( 'option_name' => $option_name ) );
3540
}
3641
}
3742
}

0 commit comments

Comments
 (0)