Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Run PHPUnit tests #99

Merged
merged 29 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0579914
CI: Run PHPUnit tests
adamziel Apr 16, 2024
a57abf0
Update PHPUnit command
adamziel Apr 16, 2024
4d339ab
Adjust composer dependencies
adamziel Apr 16, 2024
1e916bb
Update CI setup
adamziel Apr 16, 2024
3a06147
Remove testdox option
adamziel Apr 16, 2024
4feb0eb
Remove convertWarningsToExceptions etc
adamziel Apr 16, 2024
8cda908
Merge branch 'main' into phpunit-ci
aristath Apr 22, 2024
85e2ddc
Merge branch 'main' into phpunit-ci
aristath Apr 22, 2024
7f3f395
Attempt to fix CI tests
aristath Apr 24, 2024
79f753f
fix tests
aristath Apr 24, 2024
aa000f6
Indentation
aristath Apr 24, 2024
bba13cd
Use same version of phpunit as GH ubuntu-latest image
brandonpayton Apr 29, 2024
b97b8d2
Address provider-related test warnings
brandonpayton Apr 29, 2024
6838476
Get tests working but leave TODO
brandonpayton Apr 29, 2024
a337967
Fix misplaced paren in str_ends_with polyfill
brandonpayton Apr 30, 2024
f709bcf
Try to re-enable convert-to-exception settings
brandonpayton Apr 30, 2024
ee0dc2b
Fix indentation
brandonpayton Apr 30, 2024
b9c9faa
Remove unnecessary returns
brandonpayton Apr 30, 2024
928ba14
Try restoring tests for older PHP versions used by Playground
brandonpayton Apr 30, 2024
09b0c85
Try removing specific phpunit version so we can test with older PHP v…
brandonpayton Apr 30, 2024
daf9559
Restore indentation adjustment so expected/actual strings will be equal
brandonpayton Apr 30, 2024
284b2b3
Restore: Stop considering warnings, notices, and deprecations as exce…
brandonpayton Apr 30, 2024
4e74594
Restore necessary void returns 😬
brandonpayton Apr 30, 2024
cc7e327
See if tests pass again without considering errors to be exceptions
brandonpayton Apr 30, 2024
73777d7
Revert "Try removing specific phpunit version so we can test with old…
brandonpayton Apr 30, 2024
e60d7c5
Remove PHP 7.0 and 7.1 tests due to phpunit compatibility issues
brandonpayton Apr 30, 2024
9e5172c
Try tightening X-as-exception settings in config again
brandonpayton Apr 30, 2024
18c259b
Try testing with PHP 7.1 again
brandonpayton Apr 30, 2024
dfa10e1
Revert "Try testing with PHP 7.1 again"
brandonpayton Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/phpunit-tests-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Run PHPUnit tests

on:
workflow_call:
inputs:
os:
description: 'Operating system to run tests on'
required: false
type: 'string'
default: 'ubuntu-latest'
php:
description: 'The version of PHP to use, in the format of X.Y'
required: true
type: 'string'
phpunit-config:
description: 'The PHPUnit configuration file to use'
required: false
type: 'string'
default: 'phpunit.xml.dist'
env:
LOCAL_PHP: ${{ inputs.php }}-fpm
PHPUNIT_CONFIG: ${{ inputs.phpunit-config }}

jobs:
phpunit-tests:
name: ${{ inputs.os }}
runs-on: ${{ inputs.os }}
timeout-minutes: 20

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ inputs.php }}'
tools: phpunit-polyfills

- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
ignore-cache: "yes"
composer-options: "--optimize-autoloader"

- name: Run PHPUnit tests
run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist
28 changes: 28 additions & 0 deletions .github/workflows/phpunit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PHPUnit Tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: PHP ${{ matrix.php }}
uses: ./.github/workflows/phpunit-tests-run.yml
permissions:
contents: read
secrets: inherit
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
# NOTE: There does not appear to be a single phpunit version that supports all
# PHP versions tested here. For now, we are removing PHP 7.0. and 7.1 tests
# in order to run a single phpunit version for PHP 7.2 and up.
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]

with:
os: ${{ matrix.os }}
php: ${{ matrix.php }}
phpunit-config: ${{ 'phpunit.xml.dist' }}
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"issues": "https://github.com/wordpress/sqlite-database-integration/issues"
},
"require": {
"php": ">=5.6"
"php": ">=7.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"squizlabs/php_codesniffer": "^3.7",
"wp-coding-standards/wpcs": "^3.1",
"yoast/phpunit-polyfills": "^1.0.1",
"phpcompatibility/phpcompatibility-wp": "*",
"php-parallel-lint/php-parallel-lint": "^1.3"
"php-parallel-lint/php-parallel-lint": "^1.3",
"yoast/phpunit-polyfills": "2.0.0",
"phpunit/phpunit": "8.5.38"
},
"config": {
"allow-plugins": {
Expand All @@ -30,6 +31,9 @@
],
"fix-cs": [
"@php ./vendor/bin/phpcbf"
],
"test": [
"phpunit"
]
}
}
1 change: 1 addition & 0 deletions tests/WP_SQLite_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function setUpBeforeClass(): void {
$GLOBALS['wpdb']->suppress_errors = false;
$GLOBALS['wpdb']->show_errors = true;
}
return;
}

// Before each test, we create a new database
Expand Down
2 changes: 1 addition & 1 deletion tests/WP_SQLite_PDO_User_Defined_Functions_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testFieldFunction( $expected, $args ) {
);
}

public function dataProviderForTestFieldFunction() {
public static function dataProviderForTestFieldFunction() {
return array(
array( 1, array( 'a', 'a' ) ),
array( 2, array( 'User 0000019', 'User 0000018', 'User 0000019', 'User 0000020' ) ),
Expand Down
1 change: 1 addition & 0 deletions tests/WP_SQLite_Query_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function setUpBeforeClass(): void {
$GLOBALS['wpdb']->suppress_errors = false;
$GLOBALS['wpdb']->show_errors = true;
}
return;
}

/**
Expand Down
30 changes: 16 additions & 14 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function setUpBeforeClass(): void {
$GLOBALS['wpdb']->suppress_errors = false;
$GLOBALS['wpdb']->show_errors = true;
}
return;
}

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

public function regexpOperators() {
public static function regexpOperators() {
$lowercase_rss = (object) array(
'ID' => '1',
'option_name' => 'rss_123',
Expand Down Expand Up @@ -255,26 +256,27 @@ public function testSelectFromDual() {
public function testShowCreateTable1() {
$this->assertQuery(
"CREATE TABLE _tmp_table (
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
option_name VARCHAR(255) default '',
option_value TEXT NOT NULL,
UNIQUE KEY option_name (option_name),
KEY composite (option_name, option_value)
);"
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
option_name VARCHAR(255) default '',
option_value TEXT NOT NULL,
UNIQUE KEY option_name (option_name),
KEY composite (option_name, option_value)
);"
);

$this->assertQuery(
'SHOW CREATE TABLE _tmp_table;'
);
$results = $this->engine->get_query_results();
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
$this->assertEquals(
"CREATE TABLE _tmp_table (
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
`option_name` varchar(255) DEFAULT '',
`option_value` text NOT NULL,
KEY _tmp_table__composite (option_name, option_value),
UNIQUE KEY _tmp_table__option_name (option_name)
);",
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
`option_name` varchar(255) DEFAULT '',
`option_value` text NOT NULL DEFAULT '',
KEY _tmp_table__composite (option_name, option_value),
UNIQUE KEY _tmp_table__option_name (option_name)
);",
$results[0]->{'Create Table'}
);
}
Expand Down Expand Up @@ -323,7 +325,7 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
'CREATE TABLE _tmp_table (
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
`option_name` smallint NOT NULL DEFAULT 14,
`option_value` text NOT NULL,
`option_value` text NOT NULL DEFAULT \'\',
KEY _tmp_table__option_name (option_name)
);',
$results[0]->{'Create Table'}
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function str_contains( string $haystack, string $needle ) {
* @return bool
*/
function str_ends_with( string $haystack, string $needle ) {
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle );
return empty( $needle ) || substr( $haystack, -strlen( $needle ) ) === $needle;
}
}
if ( extension_loaded( 'mbstring' ) ) {
Expand Down
Loading