From 9d2bdd112e8ccb1f531ce7a45c36dfc725221bde Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Tue, 7 May 2019 18:05:45 +0200
Subject: [PATCH] Build/Tests: exit with error code 1 when WP requirements are
 not met (unit tests only)

---
 tests/phpunit/includes/bootstrap.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php
index 23faca64e5..240ffdaedc 100644
--- a/tests/phpunit/includes/bootstrap.php
+++ b/tests/phpunit/includes/bootstrap.php
@@ -46,6 +46,18 @@ if ( version_compare( tests_get_phpunit_version(), '8.0', '>=' ) ) {
 	exit( 1 );
 }
 
+$php_version = phpversion();
+include ABSPATH . '/wp-includes/version.php';
+if ( version_compare( $required_php_version, $php_version, '>' ) ) {
+	printf(
+		'ERROR: Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s. The unit tests will not be run.' . PHP_EOL,
+		$php_version,
+		$wp_version,
+		$required_php_version
+	);
+	exit( 1 );
+}
+
 if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH ) ) {
 	echo "ERROR: The /build/ directory is missing! Please run `grunt build` prior to running PHPUnit.\n";
 	exit( 1 );
-- 
2.21.0.windows.1

