Skip to content

Commit 23ed221

Browse files
adamzielaristathbrandonpayton
authored
CI: Run PHPUnit tests (#99)
Co-authored-by: Ari Stathopoulos <[email protected]> Co-authored-by: Brandon Payton <[email protected]>
1 parent 037f6ef commit 23ed221

8 files changed

+102
-19
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Run PHPUnit tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
os:
7+
description: 'Operating system to run tests on'
8+
required: false
9+
type: 'string'
10+
default: 'ubuntu-latest'
11+
php:
12+
description: 'The version of PHP to use, in the format of X.Y'
13+
required: true
14+
type: 'string'
15+
phpunit-config:
16+
description: 'The PHPUnit configuration file to use'
17+
required: false
18+
type: 'string'
19+
default: 'phpunit.xml.dist'
20+
env:
21+
LOCAL_PHP: ${{ inputs.php }}-fpm
22+
PHPUNIT_CONFIG: ${{ inputs.phpunit-config }}
23+
24+
jobs:
25+
phpunit-tests:
26+
name: ${{ inputs.os }}
27+
runs-on: ${{ inputs.os }}
28+
timeout-minutes: 20
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
- name: Set up PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: '${{ inputs.php }}'
38+
tools: phpunit-polyfills
39+
40+
- name: Install Composer dependencies
41+
uses: ramsey/composer-install@v3
42+
with:
43+
ignore-cache: "yes"
44+
composer-options: "--optimize-autoloader"
45+
46+
- name: Run PHPUnit tests
47+
run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist

.github/workflows/phpunit-tests.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: PHPUnit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: PHP ${{ matrix.php }}
12+
uses: ./.github/workflows/phpunit-tests-run.yml
13+
permissions:
14+
contents: read
15+
secrets: inherit
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os: [ ubuntu-latest ]
20+
# NOTE: There does not appear to be a single phpunit version that supports all
21+
# PHP versions tested here. For now, we are removing PHP 7.0. and 7.1 tests
22+
# in order to run a single phpunit version for PHP 7.2 and up.
23+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
24+
25+
with:
26+
os: ${{ matrix.os }}
27+
php: ${{ matrix.php }}
28+
phpunit-config: ${{ 'phpunit.xml.dist' }}

composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
"issues": "https://github.com/wordpress/sqlite-database-integration/issues"
99
},
1010
"require": {
11-
"php": ">=5.6"
11+
"php": ">=7.0"
1212
},
1313
"require-dev": {
1414
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
1515
"squizlabs/php_codesniffer": "^3.7",
1616
"wp-coding-standards/wpcs": "^3.1",
17-
"yoast/phpunit-polyfills": "^1.0.1",
1817
"phpcompatibility/phpcompatibility-wp": "*",
19-
"php-parallel-lint/php-parallel-lint": "^1.3"
18+
"php-parallel-lint/php-parallel-lint": "^1.3",
19+
"yoast/phpunit-polyfills": "2.0.0",
20+
"phpunit/phpunit": "8.5.38"
2021
},
2122
"config": {
2223
"allow-plugins": {
@@ -30,6 +31,9 @@
3031
],
3132
"fix-cs": [
3233
"@php ./vendor/bin/phpcbf"
34+
],
35+
"test": [
36+
"phpunit"
3337
]
3438
}
3539
}

tests/WP_SQLite_Metadata_Tests.php

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static function setUpBeforeClass(): void {
2424
$GLOBALS['wpdb']->suppress_errors = false;
2525
$GLOBALS['wpdb']->show_errors = true;
2626
}
27+
return;
2728
}
2829

2930
// Before each test, we create a new database

tests/WP_SQLite_PDO_User_Defined_Functions_Tests.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testFieldFunction( $expected, $args ) {
1818
);
1919
}
2020

21-
public function dataProviderForTestFieldFunction() {
21+
public static function dataProviderForTestFieldFunction() {
2222
return array(
2323
array( 1, array( 'a', 'a' ) ),
2424
array( 2, array( 'User 0000019', 'User 0000018', 'User 0000019', 'User 0000020' ) ),

tests/WP_SQLite_Query_Tests.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function setUpBeforeClass(): void {
2727
$GLOBALS['wpdb']->suppress_errors = false;
2828
$GLOBALS['wpdb']->show_errors = true;
2929
}
30+
return;
3031
}
3132

3233
/**

tests/WP_SQLite_Translator_Tests.php

+16-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static function setUpBeforeClass(): void {
2424
$GLOBALS['wpdb']->suppress_errors = false;
2525
$GLOBALS['wpdb']->show_errors = true;
2626
}
27+
return;
2728
}
2829

2930
// Before each test, we create a new database
@@ -92,7 +93,7 @@ public function testRegexps( $operator, $regexp, $expected_result ) {
9293
);
9394
}
9495

95-
public function regexpOperators() {
96+
public static function regexpOperators() {
9697
$lowercase_rss = (object) array(
9798
'ID' => '1',
9899
'option_name' => 'rss_123',
@@ -255,26 +256,27 @@ public function testSelectFromDual() {
255256
public function testShowCreateTable1() {
256257
$this->assertQuery(
257258
"CREATE TABLE _tmp_table (
258-
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
259-
option_name VARCHAR(255) default '',
260-
option_value TEXT NOT NULL,
261-
UNIQUE KEY option_name (option_name),
262-
KEY composite (option_name, option_value)
263-
);"
259+
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
260+
option_name VARCHAR(255) default '',
261+
option_value TEXT NOT NULL,
262+
UNIQUE KEY option_name (option_name),
263+
KEY composite (option_name, option_value)
264+
);"
264265
);
265266

266267
$this->assertQuery(
267268
'SHOW CREATE TABLE _tmp_table;'
268269
);
269270
$results = $this->engine->get_query_results();
271+
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
270272
$this->assertEquals(
271273
"CREATE TABLE _tmp_table (
272-
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
273-
`option_name` varchar(255) DEFAULT '',
274-
`option_value` text NOT NULL,
275-
KEY _tmp_table__composite (option_name, option_value),
276-
UNIQUE KEY _tmp_table__option_name (option_name)
277-
);",
274+
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
275+
`option_name` varchar(255) DEFAULT '',
276+
`option_value` text NOT NULL DEFAULT '',
277+
KEY _tmp_table__composite (option_name, option_value),
278+
UNIQUE KEY _tmp_table__option_name (option_name)
279+
);",
278280
$results[0]->{'Create Table'}
279281
);
280282
}
@@ -323,7 +325,7 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
323325
'CREATE TABLE _tmp_table (
324326
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
325327
`option_name` smallint NOT NULL DEFAULT 14,
326-
`option_value` text NOT NULL,
328+
`option_value` text NOT NULL DEFAULT \'\',
327329
KEY _tmp_table__option_name (option_name)
328330
);',
329331
$results[0]->{'Create Table'}

tests/bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function str_contains( string $haystack, string $needle ) {
8080
* @return bool
8181
*/
8282
function str_ends_with( string $haystack, string $needle ) {
83-
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle );
83+
return empty( $needle ) || substr( $haystack, -strlen( $needle ) ) === $needle;
8484
}
8585
}
8686
if ( extension_loaded( 'mbstring' ) ) {

0 commit comments

Comments
 (0)