diff --git a/bootstrap.php b/bootstrap.php index 6a3cda4..8970f8f 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,16 +5,17 @@ // phpcs:disable Generic.PHP.ForbiddenFunctions.Found // There are no core functions to read these constants. -define('ABSPATH', './'); +define('ABSPATH', '/'); +define('WP_CONTENT_DIR', sprintf('%swp-content', ABSPATH)); +define('WP_PLUGIN_DIR', sprintf('%s/plugins', WP_CONTENT_DIR)); +define('WPMU_PLUGIN_DIR', sprintf('%s/mu-plugins', WP_CONTENT_DIR)); define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); -define('WP_DEBUG_DISPLAY', true); -define('WP_PLUGIN_DIR', './'); -define('WPMU_PLUGIN_DIR', './'); -define('EMPTY_TRASH_DAYS', 30 * 86400); +define('WP_DEBUG_DISPLAY', false); +define('EMPTY_TRASH_DAYS', 30); define('SCRIPT_DEBUG', false); -define('WP_LANG_DIR', './'); -define('WP_CONTENT_DIR', './'); +define('WP_LANG_DIR', sprintf('%s/languages', WP_CONTENT_DIR)); +define('COOKIE_DOMAIN', ''); // Constants for expressing human-readable intervals. define('MINUTE_IN_SECONDS', 60); diff --git a/extension.neon b/extension.neon index ddb9185..9417aa4 100644 --- a/extension.neon +++ b/extension.neon @@ -38,11 +38,26 @@ parameters: - ../../php-stubs/wordpress-stubs/wordpress-stubs.php - bootstrap.php dynamicConstantNames: + # Debug constants - WP_DEBUG - WP_DEBUG_LOG - WP_DEBUG_DISPLAY - - EMPTY_TRASH_DAYS + # Directory constants + - ABSPATH + - WP_PLUGIN_DIR + - WP_LANG_DIR + - WP_CONTENT_DIR + - WPMU_PLUGIN_DIR + # Templating constants + - WP_DEFAULT_THEME + # Filesystem constants + - FS_CONNECT_TIMEOUT + - FS_TIMEOUT + - FS_CHMOD_DIR + - FS_CHMOD_FILE + # Other constants - COOKIE_DOMAIN + - EMPTY_TRASH_DAYS - SCRIPT_DEBUG earlyTerminatingFunctionCalls: - wp_send_json diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 3eef46a..4c951c7 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -5,6 +5,7 @@ tests/ tests/data/* + tests/phpstan-data/* tests/functions.php tests/WP_UnitTestCase_Base.php @@ -19,6 +20,7 @@ tests/AssertMethodTypeSpecifyingExtensionTest.php tests/DynamicReturnTypeExtensionTest.php + tests/DynamicConstantTypeTest.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fd23039..ef3b54b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,7 @@ includes: - vendor/phpstan/phpstan/conf/bleedingEdge.neon - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: level: 9 scanFiles: diff --git a/tests/DynamicConstantTypeTest.php b/tests/DynamicConstantTypeTest.php new file mode 100644 index 0000000..b42e57e --- /dev/null +++ b/tests/DynamicConstantTypeTest.php @@ -0,0 +1,30 @@ + + */ + public function dataFileAsserts(): iterable + { + yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-constants.php'); + } + + /** + * @dataProvider dataFileAsserts + * @param array ...$args + */ + public function testFileAsserts(string $assertType, string $file, ...$args): void + { + $this->assertFileAsserts($assertType, $file, ...$args); + } + + public static function getAdditionalConfigFiles(): array + { + return [dirname(__DIR__) . '/vendor/szepeviktor/phpstan-wordpress/extension.neon']; + } +} diff --git a/tests/data/dynamic-constants.php b/tests/data/dynamic-constants.php new file mode 100644 index 0000000..70bb2aa --- /dev/null +++ b/tests/data/dynamic-constants.php @@ -0,0 +1,128 @@ +