Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 82eed09

Browse files
authored
Merge pull request #42 from Automattic/driver-migration
Database configuration and migration
2 parents 4a327fb + 2a13304 commit 82eed09

28 files changed

+2589
-753
lines changed

.github/workflows/verify-version.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Verify plugin version
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
verify-version:
11+
name: Assert the WordPress plugin header declares the same version as the SQLITE_DRIVER_VERSION constant
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Extract version from "load.php"
17+
id: load_version
18+
run: |
19+
VERSION=$(grep "Version:" load.php | sed "s/.*Version: \([^ ]*\).*/\1/")
20+
echo "load_version=$VERSION" >> $GITHUB_OUTPUT
21+
22+
- name: Extract version from "version.php"
23+
id: const_version
24+
run: |
25+
VERSION=$(php -r "require 'version.php'; echo SQLITE_DRIVER_VERSION;")
26+
echo "const_version=$VERSION" >> $GITHUB_OUTPUT
27+
28+
- name: Compare versions
29+
run: |
30+
if [ "${{ steps.load_version.outputs.load_version }}" != "${{ steps.const_version.outputs.const_version }}" ]; then
31+
echo "Version mismatch detected!"
32+
echo " load.php version: ${{ steps.load_version.outputs.load_version }}"
33+
echo " version.php constant: ${{ steps.const_version.outputs.const_version }}"
34+
exit 1
35+
fi

load.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
* @package wp-sqlite-integration
1313
*/
1414

15+
/**
16+
* Load the "SQLITE_DRIVER_VERSION" constant.
17+
* This constant needs to be updated on plugin release!
18+
*/
19+
require_once __DIR__ . '/version.php';
20+
1521
define( 'SQLITE_MAIN_FILE', __FILE__ );
1622

1723
require_once __DIR__ . '/php-polyfills.php';

tests/WP_SQLite_Driver_Metadata_Tests.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
11
<?php
22

3-
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-driver.php';
4-
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-driver-exception.php';
5-
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php';
6-
73
use PHPUnit\Framework\TestCase;
84

95
class WP_SQLite_Driver_Metadata_Tests extends TestCase {
10-
6+
/** @var WP_SQLite_Driver */
117
private $engine;
12-
private $sqlite;
138

14-
public static function setUpBeforeClass(): void {
15-
// if ( ! defined( 'PDO_DEBUG' )) {
16-
// define( 'PDO_DEBUG', true );
17-
// }
18-
if ( ! defined( 'FQDB' ) ) {
19-
define( 'FQDB', ':memory:' );
20-
define( 'FQDBDIR', __DIR__ . '/../testdb' );
21-
}
22-
error_reporting( E_ALL & ~E_DEPRECATED );
23-
if ( ! isset( $GLOBALS['table_prefix'] ) ) {
24-
$GLOBALS['table_prefix'] = 'wptests_';
25-
}
26-
if ( ! isset( $GLOBALS['wpdb'] ) ) {
27-
$GLOBALS['wpdb'] = new stdClass();
28-
$GLOBALS['wpdb']->suppress_errors = false;
29-
$GLOBALS['wpdb']->show_errors = true;
30-
}
31-
return;
32-
}
9+
/** @var PDO */
10+
private $sqlite;
3311

3412
// Before each test, we create a new database
3513
public function setUp(): void {
3614
$this->sqlite = new PDO( 'sqlite::memory:' );
3715
$this->engine = new WP_SQLite_Driver(
38-
array(
39-
'connection' => $this->sqlite,
40-
'database' => 'wp',
41-
)
16+
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
17+
'wp'
4218
);
4319
}
4420

tests/WP_SQLite_Driver_Query_Tests.php

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
11
<?php
22

3-
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-driver.php';
4-
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-driver-exception.php';
5-
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php';
6-
73
use PHPUnit\Framework\TestCase;
84

95
/**
106
* Unit tests using the WordPress table definitions.
117
*/
128
class WP_SQLite_Driver_Query_Tests extends TestCase {
13-
9+
/** @var WP_SQLite_Driver */
1410
private $engine;
15-
private $sqlite;
1611

17-
public static function setUpBeforeClass(): void {
18-
// if ( ! defined( 'PDO_DEBUG' )) {
19-
// define( 'PDO_DEBUG', true );
20-
// }
21-
if ( ! defined( 'FQDB' ) ) {
22-
define( 'FQDB', ':memory:' );
23-
define( 'FQDBDIR', __DIR__ . '/../testdb' );
24-
}
25-
error_reporting( E_ALL & ~E_DEPRECATED );
26-
if ( ! isset( $GLOBALS['table_prefix'] ) ) {
27-
$GLOBALS['table_prefix'] = 'wptests_';
28-
}
29-
if ( ! isset( $GLOBALS['wpdb'] ) ) {
30-
$GLOBALS['wpdb'] = new stdClass();
31-
$GLOBALS['wpdb']->suppress_errors = false;
32-
$GLOBALS['wpdb']->show_errors = true;
33-
}
34-
return;
35-
}
12+
/** @var PDO */
13+
private $sqlite;
3614

3715
/**
3816
* Before each test, we create a new volatile database and WordPress tables.
@@ -47,10 +25,8 @@ public function setUp(): void {
4725

4826
$this->sqlite = new PDO( 'sqlite::memory:' );
4927
$this->engine = new WP_SQLite_Driver(
50-
array(
51-
'connection' => $this->sqlite,
52-
'database' => 'wp',
53-
)
28+
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
29+
'wp'
5430
);
5531

5632
$translator = $this->engine;
@@ -462,7 +438,7 @@ public function testRecoverSerialized() {
462438
);
463439
$option_name = 'serialized_option';
464440
$option_value = serialize( $obj );
465-
$option_value_escaped = $this->engine->get_pdo()->quote( $option_value );
441+
$option_value_escaped = $this->engine->get_connection()->quote( $option_value );
466442
/* Note well: this is heredoc not nowdoc */
467443
$insert = <<<QUERY
468444
INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`)
@@ -488,7 +464,7 @@ public function testRecoverSerialized() {
488464
++$obj ['two'];
489465
$obj ['pi'] *= 2;
490466
$option_value = serialize( $obj );
491-
$option_value_escaped = $this->engine->get_pdo()->quote( $option_value );
467+
$option_value_escaped = $this->engine->get_connection()->quote( $option_value );
492468
/* Note well: this is heredoc not nowdoc */
493469
$insert = <<<QUERY
494470
INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`)

0 commit comments

Comments
 (0)