Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -42,7 +43,8 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"sort-packages": true
},
"extra": {
"phpstan": {
Expand Down
15 changes: 12 additions & 3 deletions tests/DynamicReturnTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
];
}
}
29 changes: 29 additions & 0 deletions tests/InstalledPhpStanVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace SzepeViktor\PHPStan\WordPress\Tests;

use Composer\InstalledVersions;
use Composer\Semver\Semver;

final class InstalledPhpStanVersion
{
private string $version;

public function __construct()
{
$version = InstalledVersions::getVersion('phpstan/phpstan-src');

if ($version === null) {
throw new \RuntimeException('Cannot determine PHPStan version from Composer.');
}

$this->version = $version;
}

public function satisfies(string $constraints): bool
{
return Semver::satisfies($this->version, $constraints);
}
}
3 changes: 3 additions & 0 deletions tests/test-services.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
-
class: SzepeViktor\PHPStan\WordPress\Tests\InstalledPhpStanVersion