Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Tests/Unit/testBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WPMedia\PHPUnit\Tests\Unit;

use WPMedia\PHPUnit\Unit\TestCase;
use function WPMedia\PHPUnit\check_readiness;

class Test_Bootstrap extends TestCase {

Expand All @@ -16,4 +17,24 @@ function testShouldReturnTrueWhenRootBootstrapFileIsInMemory() {
$this->assertTrue( function_exists( __NAMESPACE__ . '\is_unit_test_bootstrap' ) );
$this->assertTrue( is_unit_test_bootstrap() );
}

function testShouldAcceptMinimumSupportedPhpVersion() {
$this->assertNull( check_readiness( '7.4.0' ) );
}

function testShouldRejectPhpVersionBelowSupportedMinimum() {
$error = null;
set_error_handler(
function ( $errno, $errstr ) use ( &$error ) {
$error = compact( 'errno', 'errstr' );
return true;
}
);

check_readiness( '7.3.99' );
restore_error_handler();

$this->assertSame( E_USER_ERROR, $error['errno'] );
$this->assertSame( 'Test Suite requires PHP 7.4 or higher.', $error['errstr'] );
}
}
10 changes: 7 additions & 3 deletions bootstrap-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ function init_test_suite() {

/**
* Check the system's readiness to run the tests.
*
* @param string|null $php_version PHP version to validate. Defaults to the running version.
*/
function check_readiness() {
if ( version_compare( phpversion(), '7.1.0', '<' ) ) {
trigger_error( 'Test Suite requires PHP 7.1 or higher.', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Valid use case for our testing suite.
function check_readiness( $php_version = null ) {
$php_version = $php_version ?: phpversion();

if ( version_compare( $php_version, '7.4.0', '<' ) ) {
trigger_error( 'Test Suite requires PHP 7.4 or higher.', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Valid use case for our testing suite.
}

if ( ! file_exists( WPMEDIA_PHPUNIT_ROOT_DIR . '/vendor/autoload.php' ) ) {
Expand Down