Make WordPress Core


Ignore:
Timestamp:
02/06/2020 06:31:22 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Replace dirname( __FILE__ ) calls with __DIR__ magic constant.

This avoids the performance overhead of the function call every time dirname( __FILE__ ) was used instead of __DIR__.

This commit also includes:

  • Removing unnecessary parentheses from include/require statements. These are language constructs, not function calls.
  • Replacing include statements for several files with require_once, for consistency:
    • wp-admin/admin-header.php
    • wp-admin/admin-footer.php
    • wp-includes/version.php

Props ayeshrajans, desrosj, valentinbora, jrf, joostdevalk, netweb.
Fixes #48082.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r47156 r47198  
    88 */
    99if ( class_exists( 'PHPUnit\Runner\Version' ) ) {
    10     require_once dirname( __FILE__ ) . '/phpunit6/compat.php';
     10    require_once __DIR__ . '/phpunit6/compat.php';
    1111}
    1212
     
    1414    $config_file_path = WP_TESTS_CONFIG_FILE_PATH;
    1515} else {
    16     $config_file_path = dirname( dirname( __FILE__ ) );
     16    $config_file_path = dirname( __DIR__ );
    1717    if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) {
    1818        // Support the config file from the root of the develop repository.
     
    3636
    3737require_once $config_file_path;
    38 require_once dirname( __FILE__ ) . '/functions.php';
     38require_once __DIR__ . '/functions.php';
    3939
    4040if ( version_compare( tests_get_phpunit_version(), '8.0', '>=' ) ) {
     
    5555
    5656define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
    57 define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' );
    58 define( 'DIR_TESTROOT', realpath( dirname( dirname( __FILE__ ) ) ) );
     57define( 'DIR_TESTDATA', __DIR__ . '/../data' );
     58define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) );
    5959
    6060define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' );
     
    8585
    8686// Override the PHPMailer.
    87 require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
     87require_once __DIR__ . '/mock-mailer.php';
    8888$phpmailer = new MockPHPMailer( true );
    8989
     
    9898
    9999if ( '1' !== getenv( 'WP_TESTS_SKIP_INSTALL' ) ) {
    100     system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite, $retval );
     100    system( WP_PHP_BINARY . ' ' . escapeshellarg( __DIR__ . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite, $retval );
    101101    if ( 0 !== $retval ) {
    102102        exit( $retval );
     
    140140
    141141if ( version_compare( tests_get_phpunit_version(), '7.0', '>=' ) ) {
    142     require dirname( __FILE__ ) . '/phpunit7/testcase.php';
     142    require __DIR__ . '/phpunit7/testcase.php';
    143143} else {
    144     require dirname( __FILE__ ) . '/testcase.php';
    145 }
    146 
    147 require dirname( __FILE__ ) . '/testcase-rest-api.php';
    148 require dirname( __FILE__ ) . '/testcase-rest-controller.php';
    149 require dirname( __FILE__ ) . '/testcase-rest-post-type-controller.php';
    150 require dirname( __FILE__ ) . '/testcase-xmlrpc.php';
    151 require dirname( __FILE__ ) . '/testcase-ajax.php';
    152 require dirname( __FILE__ ) . '/testcase-canonical.php';
    153 require dirname( __FILE__ ) . '/exceptions.php';
    154 require dirname( __FILE__ ) . '/utils.php';
    155 require dirname( __FILE__ ) . '/spy-rest-server.php';
    156 require dirname( __FILE__ ) . '/class-wp-rest-test-search-handler.php';
    157 require dirname( __FILE__ ) . '/class-wp-fake-block-type.php';
     144    require __DIR__ . '/testcase.php';
     145}
     146
     147require __DIR__ . '/testcase-rest-api.php';
     148require __DIR__ . '/testcase-rest-controller.php';
     149require __DIR__ . '/testcase-rest-post-type-controller.php';
     150require __DIR__ . '/testcase-xmlrpc.php';
     151require __DIR__ . '/testcase-ajax.php';
     152require __DIR__ . '/testcase-canonical.php';
     153require __DIR__ . '/exceptions.php';
     154require __DIR__ . '/utils.php';
     155require __DIR__ . '/spy-rest-server.php';
     156require __DIR__ . '/class-wp-rest-test-search-handler.php';
     157require __DIR__ . '/class-wp-fake-block-type.php';
    158158
    159159/**
Note: See TracChangeset for help on using the changeset viewer.