Skip to content

Commit 47a5084

Browse files
committed
Build/Test Tools: Improve the constants defined for PHPStan.
Many constants were defined as empty strings, including ones that never hold an empty value in a real install. Realistic values are provided for those, matching what wp-settings.php and default-constants.php would produce, so that functions building on them can be given narrower types without the placeholder itself violating them. Constants core itself defines as empty, such as WP_DEVELOPMENT_MODE and COOKIE_DOMAIN, are left as they were. Developed as subset of WordPress#11851. See #64898. git-svn-id: https://develop.svn.wordpress.org/trunk@62965 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f408760 commit 47a5084

1 file changed

Lines changed: 39 additions & 31 deletions

File tree

tests/phpstan/bootstrap.php

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
* Loaded as a `bootstrapFile` by PHPStan; see `base.neon`.
88
*/
99

10-
// wp_initial_constants()
10+
/*
11+
* A fixed, fictional path rather than the real checkout location. PHPStan resolves
12+
* no files through this constant, and deriving it from __DIR__ embeds the developer's
13+
* own path in error messages, making output differ between machines.
14+
*/
15+
define( 'ABSPATH', '/var/www/html/' );
16+
17+
/** @see wp_initial_constants() */
1118
define( 'KB_IN_BYTES', 1024 );
1219
define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
1320
define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
@@ -16,9 +23,10 @@
1623
define( 'EB_IN_BYTES', 1024 * PB_IN_BYTES );
1724
define( 'ZB_IN_BYTES', 1024 * EB_IN_BYTES );
1825
define( 'YB_IN_BYTES', 1024 * ZB_IN_BYTES );
19-
define( 'WP_START_TIMESTAMP', microtime( true ) );
20-
define( 'WP_MEMORY_LIMIT', '' );
21-
define( 'WP_MAX_MEMORY_LIMIT', '' );
26+
define( 'WP_START_TIMESTAMP', 1700000000.0 ); // Fixed rather than microtime( true ), whose value would differ on every run.
27+
define( 'WP_MEMORY_LIMIT', '40M' );
28+
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
29+
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
2230
define( 'WP_DEVELOPMENT_MODE', '' );
2331
define( 'WP_DEBUG', false );
2432
define( 'WP_DEBUG_DISPLAY', false );
@@ -35,25 +43,25 @@
3543
define( 'MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS );
3644
define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
3745

38-
// wp_set_lang_dir()
39-
define( 'WP_LANG_DIR', '' );
46+
/** @see wp_set_lang_dir() */
47+
define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
4048

4149
// wp_plugin_directory_constants()
42-
define( 'WP_CONTENT_URL', '' );
43-
define( 'WP_PLUGIN_DIR', '' );
44-
define( 'WP_PLUGIN_URL', '' );
45-
define( 'PLUGINDIR', '' );
46-
define( 'WPMU_PLUGIN_DIR', '' );
47-
define( 'WPMU_PLUGIN_URL', '' );
48-
define( 'MUPLUGINDIR', '' );
50+
define( 'WP_CONTENT_URL', 'https://example.com/wp-content' );
51+
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
52+
define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );
53+
define( 'PLUGINDIR', 'wp-content/plugins' );
54+
define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' );
55+
define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' );
56+
define( 'MUPLUGINDIR', 'wp-content/mu-plugins' );
4957

50-
// ms_cookie_constants()
58+
/** @see ms_cookie_constants() */
5159
define( 'COOKIEPATH', '' );
5260
define( 'SITECOOKIEPATH', '' );
5361
define( 'ADMIN_COOKIE_PATH', '' );
5462
define( 'COOKIE_DOMAIN', '' );
5563

56-
// wp_cookie_constants()
64+
/** @see wp_cookie_constants() */
5765
define( 'COOKIEHASH', '' );
5866
define( 'USER_COOKIE', '' );
5967
define( 'PASS_COOKIE', '' );
@@ -64,34 +72,34 @@
6472
define( 'PLUGINS_COOKIE_PATH', '' );
6573
define( 'RECOVERY_MODE_COOKIE', '' );
6674

67-
// wp_ssl_constants()
75+
/** @see wp_ssl_constants() */
6876
define( 'FORCE_SSL_LOGIN', false );
6977
define( 'FORCE_SSL_ADMIN', false );
7078

71-
// wp_functionality_constants()
79+
/** @see wp_functionality_constants() */
7280
define( 'AUTOSAVE_INTERVAL', MINUTE_IN_SECONDS );
7381
define( 'EMPTY_TRASH_DAYS', 1 );
7482
define( 'WP_POST_REVISIONS', true );
7583
define( 'WP_CRON_LOCK_TIMEOUT', MINUTE_IN_SECONDS );
7684

77-
// wp_templating_constants()
78-
define( 'TEMPLATEPATH', '' );
79-
define( 'STYLESHEETPATH', '' );
80-
define( 'WP_DEFAULT_THEME', '' );
85+
/** @see wp_templating_constants() */
86+
define( 'TEMPLATEPATH', WP_CONTENT_DIR . '/themes/twentytwentyfive' );
87+
define( 'STYLESHEETPATH', WP_CONTENT_DIR . '/themes/twentytwentyfive' );
88+
define( 'WP_DEFAULT_THEME', 'twentytwentyfive' );
8189

82-
// ms_file_constants()
90+
/** @see ms_file_constants() */
8391
define( 'WPMU_SENDFILE', false );
8492
define( 'WPMU_ACCEL_REDIRECT', false );
8593

86-
// ms_load_current_site_and_network()
94+
/** @see ms_load_current_site_and_network() */
8795
define( 'NOBLOGREDIRECT', '' );
8896

89-
// ms_upload_constants()
90-
define( 'UPLOADBLOGSDIR', '' );
91-
define( 'BLOGUPLOADDIR', '' );
97+
/** @see ms_upload_constants() */
98+
define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' );
99+
define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . '/blogs.dir/1/files/' );
92100

93-
// Misc constants not part of the default lifecycle.
94-
define( 'FS_CONNECT_TIMEOUT', 1 );
95-
define( 'FS_TIMEOUT', 1 );
96-
define( 'FS_CHMOD_DIR', 1 );
97-
define( 'FS_CHMOD_FILE', 1 );
101+
/** @see WP_Filesystem() */
102+
define( 'FS_CONNECT_TIMEOUT', 30 ); // 30 seconds.
103+
define( 'FS_TIMEOUT', 30 ); // 30 seconds.
104+
define( 'FS_CHMOD_DIR', 0755 );
105+
define( 'FS_CHMOD_FILE', 0644 );

0 commit comments

Comments
 (0)