From 74e02a21b87d48a17b6a31aaf17954eb7f2fd3fe Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 8 Mar 2017 00:06:12 +0000 Subject: [PATCH] Build/Test tools: In Travis, skip some tests when not on trunk. This skips time sensitive tests (copyright year and PHP/MySQL version requirements) when tests are run on branches on Travis. Props netweb, jorbin Fixes #39486 git-svn-id: https://develop.svn.wordpress.org/trunk@40241 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 21 +++++++++++++++++++++ tests/phpunit/tests/basic.php | 3 +++ tests/phpunit/tests/external-http/basic.php | 3 +++ 3 files changed, 27 insertions(+) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 66dc212530..e5bbdaedbb 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -176,6 +176,27 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { self::flush_cache(); } + /** + * 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. + */ + 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 ) { + $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' ); + } + } + /** * Unregister existing post types and register defaults. * diff --git a/tests/phpunit/tests/basic.php b/tests/phpunit/tests/basic.php index 2795824361..0d145f638d 100644 --- a/tests/phpunit/tests/basic.php +++ b/tests/phpunit/tests/basic.php @@ -8,6 +8,9 @@ class Tests_Basic extends WP_UnitTestCase { function test_license() { + // This test is designed to only run on trunk/master + $this->skipOnAutomatedBranches(); + $license = file_get_contents( ABSPATH . 'license.txt' ); preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches ); $this_year = date( 'Y' ); diff --git a/tests/phpunit/tests/external-http/basic.php b/tests/phpunit/tests/external-http/basic.php index 5b234a6579..e84ab6a454 100644 --- a/tests/phpunit/tests/external-http/basic.php +++ b/tests/phpunit/tests/external-http/basic.php @@ -5,6 +5,9 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { function test_readme() { + // This test is designed to only run on trunk/master + $this->skipOnAutomatedBranches(); + $readme = file_get_contents( ABSPATH . 'readme.html' ); preg_match( '#Recommendations.*PHP version ([0-9.]*)#s', $readme, $matches );