From d697471bb19f717ea0908bc215be74a148d9b24d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 20 Dec 2019 01:10:23 +0000 Subject: [PATCH] Tests: Correct the check for pull requests in `WP_UnitTestCase_Base::skipOnAutomatedBranches()`. Mark the test as failed if the environment variables are unavailable. Fixes #49050. git-svn-id: https://develop.svn.wordpress.org/trunk@47000 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index d18a584a7d..8b61afe660 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -186,16 +186,15 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { * we want to skip tests that only need to run for master. */ public function skipOnAutomatedBranches() { - // gentenv can be disabled - if ( ! function_exists( 'getenv' ) ) { - return false; - } - // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables $travis_branch = getenv( 'TRAVIS_BRANCH' ); $travis_pull_request = getenv( 'TRAVIS_PULL_REQUEST' ); - if ( false !== $travis_pull_request && 'master' !== $travis_branch ) { + if ( ! $travis_branch || ! $travis_pull_request ) { + $this->fail( 'Could not read TRAVIS_BRANCH or TRAVIS_PULL_REQUEST' ); + } + + if ( 'master' !== $travis_branch || 'false' !== $travis_pull_request ) { $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' ); } }