Skip to content

Commit f9d4e56

Browse files
authored
PHP 8.5 compatibility (#235)
Adds PHP 8.5 unit tests and fixes PHP 8.5 deprecations: - Use `PDO\SQLite` in PHP >= 8.4 - Use `PDO\Sqlite::createFunction()` instead of deprecated `PDO::sqliteCreateFunction()` - Fix `ord(): Providing an empty string is deprecated` with PHP 8.5 Fixes #234.
2 parents c96bdd7 + ca9a49f commit f9d4e56

15 files changed

+41
-23
lines changed

.github/workflows/phpunit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
os: [ ubuntu-latest ]
20-
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
20+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
2121

2222
with:
2323
os: ${{ matrix.os }}

packages/wp-mysql-proxy/tests/WP_MySQL_Proxy_PDO_Test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class WP_MySQL_Proxy_PDO_Test extends WP_MySQL_Proxy_Test {
77
public function setUp(): void {
88
parent::setUp();
99

10-
$this->pdo = new PDO(
10+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
11+
$this->pdo = new $pdo_class(
1112
sprintf( 'mysql:host=127.0.0.1;port=%d', $this->port ),
1213
'user',
1314
'password'

tests/WP_SQLite_Driver_Metadata_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class WP_SQLite_Driver_Metadata_Tests extends TestCase {
1111

1212
// Before each test, we create a new database
1313
public function setUp(): void {
14-
$this->sqlite = new PDO( 'sqlite::memory:' );
14+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
15+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
1516
$this->engine = new WP_SQLite_Driver(
1617
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
1718
'wp'

tests/WP_SQLite_Driver_Query_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public function setUp(): void {
104104
global $tables;
105105
$queries = explode( ';', $tables );
106106

107-
$this->sqlite = new PDO( 'sqlite::memory:' );
107+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
108+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
108109
$this->engine = new WP_SQLite_Driver(
109110
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
110111
'wp'

tests/WP_SQLite_Driver_Tests.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class WP_SQLite_Driver_Tests extends TestCase {
1111

1212
// Before each test, we create a new database
1313
public function setUp(): void {
14-
$this->sqlite = new PDO( 'sqlite::memory:' );
14+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
15+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
1516

1617
$this->engine = new WP_SQLite_Driver(
1718
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
@@ -6059,7 +6060,8 @@ public function testComplexInformationSchemaQueries(): void {
60596060
}
60606061

60616062
public function testDatabaseNameEmpty(): void {
6062-
$pdo = new PDO( 'sqlite::memory:' );
6063+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
6064+
$pdo = new $pdo_class( 'sqlite::memory:' );
60636065
$connection = new WP_SQLite_Connection( array( 'pdo' => $pdo ) );
60646066

60656067
$this->expectException( WP_SQLite_Driver_Exception::class );

tests/WP_SQLite_Information_Schema_Reconstructor_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function wp_get_db_schema() {
4141

4242
// Before each test, we create a new database
4343
public function setUp(): void {
44-
$this->sqlite = new PDO( 'sqlite::memory:' );
44+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
45+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
4546
$this->engine = new WP_SQLite_Driver(
4647
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
4748
'wp'

tests/WP_SQLite_Metadata_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function setUp(): void {
1414
global $blog_tables;
1515
$queries = explode( ';', $blog_tables );
1616

17-
$this->sqlite = new PDO( 'sqlite::memory:' );
17+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
18+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
1819
$this->engine = new WP_SQLite_Translator( $this->sqlite );
1920

2021
$translator = $this->engine;

tests/WP_SQLite_PDO_User_Defined_Functions_Tests.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class WP_SQLite_PDO_User_Defined_Functions_Tests extends TestCase {
99
* @dataProvider dataProviderForTestFieldFunction
1010
*/
1111
public function testFieldFunction( $expected, $args ) {
12-
$pdo = new PDO( 'sqlite::memory:' );
13-
$fns = WP_SQLite_PDO_User_Defined_Functions::register_for( $pdo );
12+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
13+
$pdo = new $pdo_class( 'sqlite::memory:' );
14+
$fns = WP_SQLite_PDO_User_Defined_Functions::register_for( $pdo );
1415

1516
$this->assertEquals(
1617
$expected,

tests/WP_SQLite_Query_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function setUp(): void {
2323
global $blog_tables;
2424
$queries = explode( ';', $blog_tables );
2525

26-
$this->sqlite = new PDO( 'sqlite::memory:' );
26+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
27+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
2728
$this->engine = new WP_SQLite_Translator( $this->sqlite );
2829

2930
$translator = $this->engine;

tests/WP_SQLite_Translator_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class WP_SQLite_Translator_Tests extends TestCase {
1111

1212
// Before each test, we create a new database
1313
public function setUp(): void {
14-
$this->sqlite = new PDO( 'sqlite::memory:' );
14+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
15+
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
1516

1617
$this->engine = new WP_SQLite_Translator( $this->sqlite );
1718
$this->engine->query(

0 commit comments

Comments
 (0)