Skip to content

Commit 4f9235d

Browse files
committed
Fix and refactor test setup
1 parent b6db826 commit 4f9235d

8 files changed

+29
-140
lines changed

tests/WP_SQLite_Driver_Metadata_Tests.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,11 @@
33
use PHPUnit\Framework\TestCase;
44

55
class WP_SQLite_Driver_Metadata_Tests extends TestCase {
6-
6+
/** @var WP_SQLite_Driver */
77
private $engine;
8-
private $sqlite;
98

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

3012
// Before each test, we create a new database
3113
public function setUp(): void {

tests/WP_SQLite_Driver_Query_Tests.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,11 @@
66
* Unit tests using the WordPress table definitions.
77
*/
88
class WP_SQLite_Driver_Query_Tests extends TestCase {
9-
9+
/** @var WP_SQLite_Driver */
1010
private $engine;
11-
private $sqlite;
1211

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

3315
/**
3416
* Before each test, we create a new volatile database and WordPress tables.

tests/WP_SQLite_Driver_Tests.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,11 @@
33
use PHPUnit\Framework\TestCase;
44

55
class WP_SQLite_Driver_Tests extends TestCase {
6-
6+
/** @var WP_SQLite_Driver */
77
private $engine;
8-
private $sqlite;
98

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

3012
// Before each test, we create a new database
3113
public function setUp(): void {

tests/WP_SQLite_Information_Schema_Reconstructor_Tests.php

-14
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ class WP_SQLite_Information_Schema_Reconstructor_Tests extends TestCase {
2121
private $sqlite;
2222

2323
public static function setUpBeforeClass(): void {
24-
if ( ! defined( 'FQDB' ) ) {
25-
define( 'FQDB', ':memory:' );
26-
define( 'FQDBDIR', __DIR__ . '/../testdb' );
27-
}
28-
error_reporting( E_ALL & ~E_DEPRECATED );
29-
if ( ! isset( $GLOBALS['table_prefix'] ) ) {
30-
$GLOBALS['table_prefix'] = 'wptests_';
31-
}
32-
if ( ! isset( $GLOBALS['wpdb'] ) ) {
33-
$GLOBALS['wpdb'] = new class() {
34-
public function set_prefix( string $prefix ): void {}
35-
};
36-
}
37-
3824
// Mock symbols that are used for WordPress table reconstruction.
3925
if ( ! defined( 'ABSPATH' ) ) {
4026
define( 'ABSPATH', __DIR__ );

tests/WP_SQLite_Metadata_Tests.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,11 @@
33
use PHPUnit\Framework\TestCase;
44

55
class WP_SQLite_Metadata_Tests extends TestCase {
6-
6+
/** @var WP_SQLite_Translator */
77
private $engine;
8-
private $sqlite;
98

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

3012
// Before each test, we create a new database
3113
public function setUp(): void {

tests/WP_SQLite_Query_Tests.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,11 @@
66
* Unit tests using the WordPress table definitions.
77
*/
88
class WP_SQLite_Query_Tests extends TestCase {
9-
9+
/** @var WP_SQLite_Translator */
1010
private $engine;
11-
private $sqlite;
1211

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

3315
/**
3416
* Before each test, we create a new volatile database and WordPress tables.

tests/WP_SQLite_Translator_Tests.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,11 @@
33
use PHPUnit\Framework\TestCase;
44

55
class WP_SQLite_Translator_Tests extends TestCase {
6-
6+
/** @var WP_SQLite_Translator */
77
private $engine;
8-
private $sqlite;
98

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

3012
// Before each test, we create a new database
3113
public function setUp(): void {

tests/bootstrap.php

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php';
2222
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-reconstructor.php';
2323

24+
// Configure the test environment.
25+
error_reporting( E_ALL & ~E_DEPRECATED );
26+
define( 'FQDB', ':memory:' );
27+
define( 'FQDBDIR', __DIR__ . '/../testdb' );
28+
29+
// Polyfill WPDB globals.
30+
$GLOBALS['table_prefix'] = 'wptests_';
31+
$GLOBALS['wpdb'] = new class() {
32+
public function set_prefix( string $prefix ): void {}
33+
};
34+
2435
/**
2536
* Polyfills for WordPress functions
2637
*/

0 commit comments

Comments
 (0)