WordPress.org

Make WordPress Core

Ticket #53363: 53363-06-fix-EOL-test-bootstrap.patch

File 53363-06-fix-EOL-test-bootstrap.patch, 4.0 KB (added by jrf, 4 months ago)

Build/Tests: fix message display in test bootstrap Any messages to the user which are echo-ed out in the test bootstrap will generally display on a command-line interface. The *nix specific "\n" line ending will be ignored on Windows, making the messages less readable. For new lines in CLI messages, PHP_EOL should be used instead. This was already done in a few places in the script, but not consistently so. Fixed now.

  • tests/phpunit/includes/bootstrap.php

    From d69f192dad806a3c1e15fa8b8218d1851f60bd37 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sat, 7 Aug 2021 00:57:13 +0200
    Subject: [PATCH] Build/Tests: fix message display in test bootstrap
    
    Any messages to the user which are echo-ed out in the test bootstrap will generally display on a command-line interface.
    
    The *nix specific `"\n"` line ending will be ignored on Windows, making the messages less readable.
    
    For new lines in CLI messages, `PHP_EOL` should be used instead.
    
    This was already done in a few places in the script, but not consistently so. Fixed now.
    ---
     tests/phpunit/includes/bootstrap.php | 26 +++++++++++++-------------
     1 file changed, 13 insertions(+), 13 deletions(-)
    
    diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php
    index 0af29cc287..99f2f88eca 100644
    a b if ( defined( 'WP_TESTS_CONFIG_FILE_PATH' ) ) { 
    2323global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer, $wp_theme_directories;
    2424
    2525if ( ! is_readable( $config_file_path ) ) {
    26         echo "Error: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n";
     26        echo 'Error: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.', PHP_EOL;
    2727        exit( 1 );
    2828}
    2929
    require_once $config_file_path; 
    3131require_once __DIR__ . '/functions.php';
    3232
    3333if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH ) ) {
    34         echo "Error: The /build/ directory is missing! Please run `npm run build` prior to running PHPUnit.\n";
     34        echo 'Error: The /build/ directory is missing! Please run `npm run build` prior to running PHPUnit.', PHP_EOL;
    3535        exit( 1 );
    3636}
    3737
    $phpunit_version = tests_get_phpunit_version(); 
    3939
    4040if ( version_compare( $phpunit_version, '5.7.21', '<' ) ) {
    4141        printf(
    42                 "Error: Looks like you're using PHPUnit %s. WordPress requires at least PHPUnit 5.7.21.\n",
     42                'Error: Looks like you're using PHPUnit %s. WordPress requires at least PHPUnit 5.7.21.',
    4343                $phpunit_version
    44         );
    45         echo "Please use the latest PHPUnit version supported for the PHP version you are running the tests on.\n";
     44        ) . PHP_EOL;
     45        echo 'Please use the latest PHPUnit version supported for the PHP version you are running the tests on.', PHP_EOL;
    4646        exit( 1 );
    4747}
    4848
    4949// Check that the PHPUnit Polyfills autoloader exists.
    5050$phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
    5151if ( ! file_exists( $phpunit_polyfills_autoloader ) ) {
    52         echo "Error: You need to run `composer update` before running the tests.\n";
    53         echo "You can still use a PHPUnit phar to run them, but the dependencies do need to be installed.\n";
     52        echo 'Error: You need to run `composer update` before running the tests.', PHP_EOL;
     53        echo 'You can still use a PHPUnit phar to run them, but the dependencies do need to be installed.', PHP_EOL;
    5454        exit( 1 );
    5555}
    5656
    if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { 
    6969
    7070        if ( $missing_extensions ) {
    7171                printf(
    72                         "Error: The following required PHP extensions are missing from the testing environment: %s.\n",
     72                        'Error: The following required PHP extensions are missing from the testing environment: %s.',
    7373                        implode( ', ', $missing_extensions )
    74                 );
    75                 echo "Please make sure they are installed and enabled.\n",
     74                ) . PHP_EOL;
     75                echo 'Please make sure they are installed and enabled.', PHP_EOL,
    7676                exit( 1 );
    7777        }
    7878}
    foreach ( $required_constants as $constant ) { 
    9393
    9494if ( $missing_constants ) {
    9595        printf(
    96                 "Error: The following required constants are not defined: %s.\n",
     96                'Error: The following required constants are not defined: %s.',
    9797                implode( ', ', $missing_constants )
    98         );
    99         echo "Please check out `wp-tests-config-sample.php` for an example.\n",
     98        ) . PHP_EOL;
     99        echo 'Please check out `wp-tests-config-sample.php` for an example.', PHP_EOL,
    100100        exit( 1 );
    101101}
    102102