From 86ec4610e695ff8e0851af7c0508a2235ac7e6d5 Mon Sep 17 00:00:00 2001 From: NasirNobin Date: Mon, 10 Jan 2022 13:14:09 +0600 Subject: [PATCH] GitHub Actions - Example Added --- .github/workflows/test.yml | 55 ++++++++++++++++++++++++++++++++++++++ composer.json | 5 ++++ tests/wp-config.php | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..24ee507 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 \ No newline at end of file diff --git a/composer.json b/composer.json index 7870e34..eda5227 100644 --- a/composer.json +++ b/composer.json @@ -25,5 +25,10 @@ }, "scripts": { "test": "phpunit" + }, + "config": { + "allow-plugins": { + "roots/wordpress-core-installer": true + } } } diff --git a/tests/wp-config.php b/tests/wp-config.php index 012dd3a..0cd0f35 100644 --- a/tests/wp-config.php +++ b/tests/wp-config.php @@ -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' , '' );