Make WordPress Core

Ticket #53363: 53363-09-test-bootstrap-improve-error-msg.patch

File 53363-09-test-bootstrap-improve-error-msg.patch, 2.2 KB (added by jrf, 21 months ago)

Tests bootstrap: improve an outdated error condition The PHPUnit tests are/should generally be run on the src directory, so changes just made can be tested. While testing via the build directory is also still supported, this is not the default. This was last changed in [50441], but that commit did not remove/update the error message thrown by the test bootstrap file. This last change also did not take into account that that change meant that people had to update their own wptests-config.php file to match the change made in Core and would otherwise still get the outdated error message. This commit changes the messaging in the test bootstrap file to be more in line with the current reality, while still accounting for the fact that tests can be run from both src as well as build`.

  • tests/phpunit/includes/bootstrap.php

    From 0a8f9d3cb7353f98adaee7083cc1a96c283a01c5 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Thu, 26 Aug 2021 17:13:27 +0200
    Subject: [PATCH] Tests bootstrap: improve an outdated error condition
    
    The PHPUnit tests are/should generally be run on the `src` directory, so changes just made can be tested.
    While testing via the `build` directory is also still supported, this is not the default.
    
    This was last changed in [50441], but that commit did not remove/update the error message thrown by the test bootstrap file.
    
    This last change also did not take into account that that change meant that people had to update their own `wp`tests-config.php` file to match the change made in Core and would otherwise still get the outdated error message.
    
    This commit changes the messaging in the test bootstrap file to be more in line with the current reality, while still accounting for the fact that tests can be run from both `src` as well as `build`.
    ---
     tests/phpunit/includes/bootstrap.php | 14 ++++++++++++--
     1 file changed, 12 insertions(+), 2 deletions(-)
    
    diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php
    index 9a4e5fc160..dfb858c8c9 100644
    a b 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.' . PHP_EOL;
    35         exit( 1 );
     34        if ( substr( ABSPATH, -7 ) !== '/build/' ) {
     35                printf(
     36                        'Error: The ABSPATH constant in the `wp-tests-config.php` file is set to a non-existent path "%s". Please verify.' . PHP_EOL,
     37                        ABSPATH
     38                );
     39                exit( 1 );
     40        } else {
     41                echo 'Error: The PHPUnit tests should be run on the /src/ directory, not the /build/ directory.'
     42                        . ' Please update the ABSPATH constant in your `wp-tests-config.php` file to `dirname( __FILE__ ) . \'/src/\'`'
     43                        . ' or run `npm run build` prior to running PHPUnit.' . PHP_EOL;
     44                exit( 1 );
     45        }
    3646}
    3747
    3848$phpunit_version = tests_get_phpunit_version();