Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Jun 11, 2022
1 parent 49ddbdf commit c048a9f
Show file tree
Hide file tree
Showing 12 changed files with 2,281 additions and 11 deletions.
46 changes: 45 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Set up WordPress and WordPress Test Library
id: set1
uses: ./
with:
version: latest
Expand All @@ -47,3 +46,48 @@ jobs:
test -e /tmp/wordpress
test -e /tmp/wordpress-tests-lib
test -f /tmp/wordpress-tests-lib/wp-tests-config.php
integration:
name: Integration testing
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:latest
ports:
- '3306:3306'
env:
MYSQL_ROOT_PASSWORD: wordpress
MARIADB_INITDB_SKIP_TZINFO: 1
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_DATABASE: wordpress_test
steps:
- name: Check out the source code
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Set up PHP
uses: shivammathur/[email protected]
with:
coverage: none
php-version: "8.0"

- name: Install PHP Dependencies
uses: ramsey/[email protected]
with:
working-directory: wptest

- name: Set up WordPress and WordPress Test Library
uses: ./
with:
version: latest

- name: Verify MariaDB connection
run: |
while ! mysqladmin ping -h 127.0.0.1 -P ${{ job.services.mysql.ports[3306] }} --silent; do
sleep 1
done
timeout-minutes: 1

- name: Run tests
run: vendor/bin/phpunit
working-directory: wptest
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,70 @@ This action sets up WordPress and WordPress Test Library. WordPress plugins can
* `version`: WordPress version to use. Can be `trunk` or `nightly` for the latest nightly build, `latest` for the latest available WordPress release, an explicit version number (like `6.0`) to install the specific WordPress version, or a partial version (`5.9.x`) to install the latest available patch for the specific WordPress release. The default value is `latest`.
* `cache`: whether to use cached WordPress and WordPress Test Library. The default value is `true`. Nightly releases are never cached;
* `dir`: target directory for WordPress and WordPress Test Library; the default value is `/tmp`. **Warning:** the system will delete `wordpress`, `wordpress-test-library`, and `wordpress.zip` from that directory if they exist.
* `db_user`: database user for WordPress, `root` by default;
* `db_password`: database password for WordPress, empty by default;
* `db_user`: database user for WordPress, `wordpress` by default;
* `db_password`: database password for WordPress, `wordpress` by default;
* `db_name`: database name for WordPress, `wordpress_test` by default. **Warning:** WordPress Test Library may delete all tables from that database;
* `db_host`: database host (`localhost` by default) for WordPress.
* `db_host`: database host (`127.0.0.1` by default) for WordPress.

## Outputs

* `wp_version`: the actual WordPress version.

## Environment Variables

Upon success, the action sets the `WP_TESTS_DIR` environment variable; its value is the absolute path to the WordPress Test library

## Example usage

TBD.
```yaml
name: CI

on:
push:

permissions:
contents: read

jobs:
testing:
name: Run tests
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:latest
ports:
- '3306:3306'
env:
MYSQL_ROOT_PASSWORD: wordpress
MARIADB_INITDB_SKIP_TZINFO: 1
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_DATABASE: wordpress_test
steps:
- name: Check out the source code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/[email protected]
with:
coverage: none
php-version: "8.0"

- name: Install PHP Dependencies
uses: ramsey/[email protected]

- name: Set up WordPress and WordPress Test Library
uses: sjinks/setup-wordpress-test-library
with:
version: latest

- name: Verify MariaDB connection
run: |
while ! mysqladmin ping -h 127.0.0.1 -P ${{ job.services.mysql.ports[3306] }} --silent; do
sleep 1
done
timeout-minutes: 1

- name: Run tests
run: vendor/bin/phpunit
```
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ inputs:
db_user:
description: 'Database user'
required: false
default: 'root'
default: 'wordpress'
db_password:
description: 'Database password'
required: false
default: ''
default: 'wordpress'
db_name:
description: 'Database name'
required: false
default: 'wordpress_test'
db_host:
description: 'Database host'
required: false
default: 'localhost'
default: '127.0.0.1'

outputs:
wp_version:
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'<rootDir>/dist/',
'<rootDir>/lib/',
'<rootDir>/node_modules/',
'<rootDir>/wptest/',
],
testResultsProcessor: 'jest-sonar-reporter',
reporters: [
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function getInputs(): Inputs {
version: core.getInput('version', options) || 'latest',
cache: core.getBooleanInput('cache', options) && process.env.RUNNER_TOOL_CACHE !== undefined,
dir: core.getInput('dir', options) || tmpdir(),
db_user: core.getInput('db_user', options) || 'root',
db_password: core.getInput('db_password', options) || '',
db_user: core.getInput('db_user', options) || 'wordpress',
db_password: core.getInput('db_password', options) || 'wordpress',
db_name: core.getInput('db_name', options) || 'wordpress_test',
db_host: core.getInput('db_host', options) || 'localhost',
db_host: core.getInput('db_host', options) || '127.0.0.1',
};

result.dir = path.resolve(result.dir);
Expand Down
2 changes: 2 additions & 0 deletions wptest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/.phpunit.result.cache
6 changes: 6 additions & 0 deletions wptest/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require-dev": {
"phpunit/phpunit": "^9.5",
"yoast/phpunit-polyfills": "^1.0"
}
}
Loading

0 comments on commit c048a9f

Please sign in to comment.