From 91b5e5255ea398abe76385ceac5a9acb503c5cc6 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Wed, 21 Oct 2020 19:55:17 +0000 Subject: [PATCH] Build/Test Tools: Pass GitHub Action related environment variables to the Docker container. This ensures that `WP_UnitTestCase::skipOnAutomatedBranches()` has access to these variables so that time sensitive tests can be skipped when appropriate. This also updates that logic to be more clear. Follow up to [49264]. Props ocean90, johnbillion. See #50401, #49050, #47767. git-svn-id: https://develop.svn.wordpress.org/trunk@49267 602fd350-edb4-49c9-b593-d223f7449a82 --- docker-compose.yml | 2 ++ tests/phpunit/includes/abstract-testcase.php | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3d0ff62cd5..eddc4a5670 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -110,6 +110,8 @@ services: PHP_FPM_GID: ${PHP_FPM_GID-1000} TRAVIS_BRANCH: ${TRAVIS_BRANCH-false} TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST-false} + GITHUB_REF: ${GITHUB_REF-false} + GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME-false} volumes: - ./tools/local-env/phpunit-config.ini:/usr/local/etc/php/conf.d/phpunit-config.ini diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index bbc365f671..4bc966fdb7 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -193,14 +193,18 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { $github_event_name = getenv( 'GITHUB_EVENT_NAME' ); $github_ref = getenv( 'GITHUB_REF' ); - if ( ( ! $travis_branch || ! $travis_pull_request ) && ! $github_event_name ) { - return; - } + if ( 'false' !== $github_event_name ) { + // We're on GitHub Actions. + $skipped = array( 'pull_request', 'pull_request_target' ); - if ( ( 'master' !== $travis_branch || 'false' !== $travis_pull_request ) && empty( $github_event_name ) ) { - $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' ); - } elseif ( in_array( $github_event_name, array( 'pull_request', 'pull_request_target' ), true ) || 'refs/heads/master' !== $github_ref ) { - $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' ); + if ( in_array( $github_event_name, $skipped, true ) || 'refs/heads/master' !== $github_ref ) { + $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master - GitHub only' ); + } + } elseif ( 'false' !== $travis_branch ) { + // We're on Travis CI. + if ( 'master' !== $travis_branch || 'false' !== $travis_pull_request ) { + $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master - Travis only' ); + } } }