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

Example for GitHub Actions #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Run Tests"

on: [ push ]

jobs:
test:
runs-on: ubuntu-latest

env:
WP_DB_HOST: 127.0.0.1
WP_DB_NAME: wp_phpunit_tests
WP_DB_USER: root
WP_DB_PASS: ""

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: wp_phpunit_tests
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: false
matrix:
php: [ 8.0, 7.4, 5.6 ]
wordpress: [ 5.8.* ]

name: php${{ matrix.php }} - wp${{ matrix.wordpress }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: wp
coverage: none

- name: Install dependencies
run: |
composer require --no-update --dev roots/wordpress:${{ matrix.wordpress }} wp-phpunit/wp-phpunit:${{ matrix.wordpress }}
[ ${{ matrix.php }} == 8 ] || composer install
# Temporary hack to allow installing PHPUnit 7 with PHP 8 until WP 5.9.
# as WP PHPUnit does not allow PHPUnit higher than 7 yet.
# See https://github.com/WordPress/wordpress-develop/commit/8def694fe4c5df95f8e20e40389faf9cb92b6dca
[ ${{ matrix.php }} != 8 ] || composer install --ignore-platform-reqs
composer show

- name: Execute tests
run: composer test
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
},
"scripts": {
"test": "phpunit"
},
"config": {
"allow-plugins": {
"roots/wordpress-core-installer": true
}
Comment on lines +29 to +32
Copy link
Author

@NasirNobin NasirNobin Jan 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to remove the composer warning.

You have until July 2022 to add the setting. Composer will then switch the default behavior to disallow all plugins.

}
}
2 changes: 1 addition & 1 deletion tests/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
define( 'DB_NAME' , getenv( 'WP_DB_NAME' ) ?: 'wp_phpunit_tests' );
define( 'DB_USER' , getenv( 'WP_DB_USER' ) ?: 'root' );
define( 'DB_PASSWORD' , getenv( 'WP_DB_PASS' ) ?: '' );
define( 'DB_HOST' , 'localhost' );
define( 'DB_HOST' , getenv( 'WP_DB_HOST' ) ?: 'localhost' );
define( 'DB_CHARSET' , 'utf8' );
define( 'DB_COLLATE' , '' );

Expand Down