diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 79276c0174..bbc365f671 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -181,19 +181,25 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { /** * Allow tests to be skipped on some automated runs. * - * For test runs on Travis for something other than trunk/master - * we want to skip tests that only need to run for master. + * For test runs on Travis/GitHub Actions for something other than trunk/master, we want to skip tests that + * only need to run for master. */ public function skipOnAutomatedBranches() { // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables $travis_branch = getenv( 'TRAVIS_BRANCH' ); $travis_pull_request = getenv( 'TRAVIS_PULL_REQUEST' ); - if ( ! $travis_branch || ! $travis_pull_request ) { + // https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables + $github_event_name = getenv( 'GITHUB_EVENT_NAME' ); + $github_ref = getenv( 'GITHUB_REF' ); + + if ( ( ! $travis_branch || ! $travis_pull_request ) && ! $github_event_name ) { return; } - if ( 'master' !== $travis_branch || 'false' !== $travis_pull_request ) { + 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' ); } }