From fdc6fe26f208f029097718a4cd1036f383eff6ff Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 2 Jan 2021 12:19:41 +0000 Subject: [PATCH] Build/Test Tools: Check if Travis/GitHub Actions environment variables are defined. This adjusts the logic for determining whether to skip some tests when not in the primary branch, and allows for running these tests locally. Follow-up to [47000], [47001], [49264], [49267], [49280]. See #50401. git-svn-id: https://develop.svn.wordpress.org/trunk@49916 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 39aa893295..4dbbea959f 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -181,8 +181,8 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { /** * Allow tests to be skipped on some automated runs. * - * 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. + * 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 @@ -193,14 +193,14 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { $github_event_name = getenv( 'GITHUB_EVENT_NAME' ); $github_ref = getenv( 'GITHUB_REF' ); - if ( 'false' !== $github_event_name ) { + if ( $github_event_name && 'false' !== $github_event_name ) { // We're on GitHub Actions. $skipped = array( 'pull_request', 'pull_request_target' ); 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' ); } - } elseif ( 'false' !== $travis_branch ) { + } elseif ( $travis_branch && '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' );