From 1d052c9aa5167163e9386a0bca90c1954ea61756 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Mon, 30 Jan 2023 14:02:24 +0000 Subject: [PATCH] Ruleset Tests: Work around WPCS trim() bug PHP 8.1 increased the strictness of types used with native functions, and this meant WPCS 2.3.0 had a bug: https://github.com/WordPress/WordPress-Coding-Standards/issues/2035 For the VIPCS ruleset tests with PHP 8.1 or above it would skip over a bunch of lines, and mark other lines as expecting errors or warnings incorrectly. Running: ``` vendor/squizlabs/php_codesniffer/bin/phpcs --standard=WordPressVIPMinimum --severity=1 WordPressVIPMinimum/ruleset-test.inc -s ``` ...shows all the expected violations, but also this for line 1: > An error occurred during processing; checking has been aborted. The error message was: trim(): Passing null to parameter #1 ($string) of type string is deprecated in .../vipcs/vendor/wp-coding-standards/wpcs/WordPress/Sniff.php on line 1144 (Internal.Exception) Line 1144 relate to the retrieval of the `minimum_supported_wp_version` config value. Since it appeared to be coming through as null, the RulesetTest.php now includes setting this as a command-line argument when PHPCS is called to run the ruleset test. When WPCS 3.0 is the minimum supported, these changes can be reverted. --- tests/RulesetTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/RulesetTest.php b/tests/RulesetTest.php index 0a9de437..ca9b15d0 100644 --- a/tests/RulesetTest.php +++ b/tests/RulesetTest.php @@ -146,7 +146,7 @@ private function collect_phpcs_result() { } $shell = sprintf( - '%1$s%2$s --severity=1 --standard=%3$s --report=json ./%3$s/ruleset-test.inc', + '%1$s%2$s --severity=1 --standard=%3$s --report=json --runtime-set minimum_supported_wp_version 0 ./%3$s/ruleset-test.inc', $php, // Current PHP executable if available. $this->phpcs_bin, $this->ruleset