Skip to content

Commit

Permalink
CI: Run PHPUnit tests (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: Ari Stathopoulos <[email protected]>
Co-authored-by: Brandon Payton <[email protected]>
  • Loading branch information
3 people authored Apr 30, 2024
1 parent 037f6ef commit 23ed221
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 19 deletions.
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

0 comments on commit 23ed221

Please sign in to comment.