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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47198 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-02-06 06:31:22 +00:00
parent b02e49c2e8
commit e72fff9cef
304 changed files with 1068 additions and 1063 deletions

View File

@@ -1,7 +1,7 @@
<?php
require_once dirname( __FILE__ ) . '/factory.php';
require_once dirname( __FILE__ ) . '/trac.php';
require_once __DIR__ . '/factory.php';
require_once __DIR__ . '/trac.php';
/**
* Defines a basic fixture to run multiple tests.

View File

@@ -7,13 +7,13 @@
* Compatibility with PHPUnit 6+
*/
if ( class_exists( 'PHPUnit\Runner\Version' ) ) {
require_once dirname( __FILE__ ) . '/phpunit6/compat.php';
require_once __DIR__ . '/phpunit6/compat.php';
}
if ( defined( 'WP_TESTS_CONFIG_FILE_PATH' ) ) {
$config_file_path = WP_TESTS_CONFIG_FILE_PATH;
} else {
$config_file_path = dirname( dirname( __FILE__ ) );
$config_file_path = dirname( __DIR__ );
if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) {
// Support the config file from the root of the develop repository.
if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) {
@@ -35,7 +35,7 @@ if ( ! is_readable( $config_file_path ) ) {
}
require_once $config_file_path;
require_once dirname( __FILE__ ) . '/functions.php';
require_once __DIR__ . '/functions.php';
if ( version_compare( tests_get_phpunit_version(), '8.0', '>=' ) ) {
printf(
@@ -54,8 +54,8 @@ if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH )
tests_reset__SERVER();
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' );
define( 'DIR_TESTROOT', realpath( dirname( dirname( __FILE__ ) ) ) );
define( 'DIR_TESTDATA', __DIR__ . '/../data' );
define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) );
define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' );
@@ -84,7 +84,7 @@ $multisite = $multisite || ( defined( 'WP_TESTS_MULTISITE' ) && WP_TESTS_MULTISI
$multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE );
// Override the PHPMailer.
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
require_once __DIR__ . '/mock-mailer.php';
$phpmailer = new MockPHPMailer( true );
if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
@@ -97,7 +97,7 @@ if ( file_exists( DIR_TESTDATA . '/themedir1' ) ) {
}
if ( '1' !== getenv( 'WP_TESTS_SKIP_INSTALL' ) ) {
system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite, $retval );
system( WP_PHP_BINARY . ' ' . escapeshellarg( __DIR__ . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite, $retval );
if ( 0 !== $retval ) {
exit( $retval );
}
@@ -139,22 +139,22 @@ require_once ABSPATH . '/wp-settings.php';
_delete_all_posts();
if ( version_compare( tests_get_phpunit_version(), '7.0', '>=' ) ) {
require dirname( __FILE__ ) . '/phpunit7/testcase.php';
require __DIR__ . '/phpunit7/testcase.php';
} else {
require dirname( __FILE__ ) . '/testcase.php';
require __DIR__ . '/testcase.php';
}
require dirname( __FILE__ ) . '/testcase-rest-api.php';
require dirname( __FILE__ ) . '/testcase-rest-controller.php';
require dirname( __FILE__ ) . '/testcase-rest-post-type-controller.php';
require dirname( __FILE__ ) . '/testcase-xmlrpc.php';
require dirname( __FILE__ ) . '/testcase-ajax.php';
require dirname( __FILE__ ) . '/testcase-canonical.php';
require dirname( __FILE__ ) . '/exceptions.php';
require dirname( __FILE__ ) . '/utils.php';
require dirname( __FILE__ ) . '/spy-rest-server.php';
require dirname( __FILE__ ) . '/class-wp-rest-test-search-handler.php';
require dirname( __FILE__ ) . '/class-wp-fake-block-type.php';
require __DIR__ . '/testcase-rest-api.php';
require __DIR__ . '/testcase-rest-controller.php';
require __DIR__ . '/testcase-rest-post-type-controller.php';
require __DIR__ . '/testcase-xmlrpc.php';
require __DIR__ . '/testcase-ajax.php';
require __DIR__ . '/testcase-canonical.php';
require __DIR__ . '/exceptions.php';
require __DIR__ . '/utils.php';
require __DIR__ . '/spy-rest-server.php';
require __DIR__ . '/class-wp-rest-test-search-handler.php';
require __DIR__ . '/class-wp-fake-block-type.php';
/**
* A class to handle additional command line arguments passed to the script.

View File

@@ -1,14 +1,14 @@
<?php
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-thing.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-post.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-bookmark.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-attachment.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-user.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-comment.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-blog.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-network.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-for-term.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-generator-sequence.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory-callback-after-create.php' );
require_once( dirname( __FILE__ ) . '/factory/class-wp-unittest-factory.php' );
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-thing.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-post.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-bookmark.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-attachment.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-user.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-comment.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-blog.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-network.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-for-term.php';
require_once __DIR__ . '/factory/class-wp-unittest-generator-sequence.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory-callback-after-create.php';
require_once __DIR__ . '/factory/class-wp-unittest-factory.php';

View File

@@ -11,7 +11,7 @@ $multisite = ! empty( $argv[2] );
define( 'WP_INSTALLING', true );
require_once $config_file_path;
require_once dirname( __FILE__ ) . '/functions.php';
require_once __DIR__ . '/functions.php';
// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme.
if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
@@ -33,10 +33,10 @@ require_once ABSPATH . '/wp-includes/wp-db.php';
// Override the PHPMailer.
global $phpmailer;
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
require_once __DIR__ . '/mock-mailer.php';
$phpmailer = new MockPHPMailer();
register_theme_directory( dirname( __FILE__ ) . '/../data/themedir1' );
register_theme_directory( __DIR__ . '/../data/themedir1' );
/*
* default_storage_engine and storage_engine are the same option, but storage_engine

View File

@@ -1,7 +1,7 @@
<?php
if ( version_compare( tests_get_phpunit_version(), '7.0', '>=' ) ) {
require dirname( __FILE__ ) . '/phpunit7/speed-trap-listener.php';
require __DIR__ . '/phpunit7/speed-trap-listener.php';
} else {
require dirname( __FILE__ ) . '/speed-trap-listener.php';
require __DIR__ . '/speed-trap-listener.php';
}

View File

@@ -1,5 +1,5 @@
<?php
require_once( ABSPATH . '/wp-includes/class-phpmailer.php' );
require_once ABSPATH . '/wp-includes/class-phpmailer.php';
class MockPHPMailer extends PHPMailer {
var $mock_sent = array();

View File

@@ -1,6 +1,6 @@
<?php
require_once dirname( dirname( __FILE__ ) ) . '/abstract-testcase.php';
require_once dirname( __DIR__ ) . '/abstract-testcase.php';
/**
* Defines a basic fixture to run multiple tests.

View File

@@ -1,7 +1,7 @@
<?php
include_once( ABSPATH . 'wp-admin/includes/admin.php' );
include_once( ABSPATH . WPINC . '/class-IXR.php' );
include_once( ABSPATH . WPINC . '/class-wp-xmlrpc-server.php' );
require_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . WPINC . '/class-IXR.php';
require_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php';
class WP_XMLRPC_UnitTestCase extends WP_UnitTestCase {
protected $myxmlrpcserver;

View File

@@ -1,6 +1,6 @@
<?php
require_once dirname( __FILE__ ) . '/abstract-testcase.php';
require_once __DIR__ . '/abstract-testcase.php';
/**
* Defines a basic fixture to run multiple tests.