diff --git a/composer.json b/composer.json index 602a473..e7230f4 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,11 @@ "require": { "php": "^7.4 || ^8.0", "php-stubs/wordpress-stubs": "^6.6.2", - "phpstan/phpstan": "^2.1.18" + "phpstan/phpstan": "^2.0" }, "require-dev": { "composer/composer": "^2.1.14", + "composer/semver": "^3.4", "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "php-parallel-lint/php-parallel-lint": "^1.1", "phpstan/phpstan-strict-rules": "^2.0", @@ -42,7 +43,8 @@ "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true - } + }, + "sort-packages": true }, "extra": { "phpstan": { diff --git a/tests/DynamicReturnTypeExtensionTest.php b/tests/DynamicReturnTypeExtensionTest.php index 4f3df6c..5f1c3bb 100644 --- a/tests/DynamicReturnTypeExtensionTest.php +++ b/tests/DynamicReturnTypeExtensionTest.php @@ -11,13 +11,19 @@ class DynamicReturnTypeExtensionTest extends \PHPStan\Testing\TypeInferenceTestC */ public function dataFileAsserts(): iterable { - // Path to a file with actual asserts of expected types: + $phpstanVersion = self::getContainer()->getByType(InstalledPhpStanVersion::class); + + if ($phpstanVersion->satisfies('^2.1.18')) { + // Improved rtrim handling in PHPStan 2.1.18 gives different results + yield from self::gatherAssertTypes(__DIR__ . '/data/slashit-functions.php'); + } + + // Include for all supported PHPStan versions yield from self::gatherAssertTypes(__DIR__ . '/data/apply-filters.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/ApplyFiltersTestClass.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/esc-sql.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/normalize-whitespace.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/shortcode-atts.php'); - yield from self::gatherAssertTypes(__DIR__ . '/data/slashit-functions.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/stripslashes-from-strings-only.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/wp-parse-url.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/wp-slash.php'); @@ -34,6 +40,9 @@ public function testFileAsserts(string $assertType, string $file, ...$args): voi public static function getAdditionalConfigFiles(): array { - return [dirname(__DIR__) . '/vendor/szepeviktor/phpstan-wordpress/extension.neon']; + return [ + dirname(__DIR__) . '/vendor/szepeviktor/phpstan-wordpress/extension.neon', + __DIR__ . '/test-services.neon', + ]; } } diff --git a/tests/InstalledPhpStanVersion.php b/tests/InstalledPhpStanVersion.php new file mode 100644 index 0000000..90b4eae --- /dev/null +++ b/tests/InstalledPhpStanVersion.php @@ -0,0 +1,29 @@ +version = $version; + } + + public function satisfies(string $constraints): bool + { + return Semver::satisfies($this->version, $constraints); + } +} diff --git a/tests/test-services.neon b/tests/test-services.neon new file mode 100644 index 0000000..e453d3b --- /dev/null +++ b/tests/test-services.neon @@ -0,0 +1,3 @@ +services: + - + class: SzepeViktor\PHPStan\WordPress\Tests\InstalledPhpStanVersion