From 90e013c3a8f5f7dc6d52735f913781957b8f20a4 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 28 Mar 2026 00:40:10 +0000 Subject: [PATCH] work on fixing CI, fixes #66 --- .github/workflows/tests.yaml | 7 +++--- composer.json | 7 +++--- phpstan.neon | 5 ++-- tests/Type/Php/TypeAssertionsTest.php | 29 +++++++++++++++++++++- tests/Type/Php/data/json_decode_return.php | 3 +++ 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 84f38f8..313ef1d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,7 +1,7 @@ name: CI on: - pull_request: ~ + pull_request: push: branches: - master @@ -19,6 +19,7 @@ jobs: - "8.2" - "8.3" - "8.4" + - "8.5" dependencies: - "highest" include: @@ -29,14 +30,14 @@ jobs: name: PHP ${{ matrix.php }} ${{ matrix.description }} steps: - name: "Checkout" - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: "Install PHP" uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} coverage: xdebug - name: "Install dependencies" - uses: ramsey/composer-install@v3 + uses: ramsey/composer-install@v4 with: dependency-versions: ${{ matrix.dependencies }} - name: "Run PHPStan analysis" diff --git a/composer.json b/composer.json index 5dab0eb..3ab7df2 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "$schema": "https://getcomposer.org/schema.json", "name": "thecodingmachine/phpstan-safe-rule", "description": "A PHPStan rule to detect safety issues. Must be used in conjunction with thecodingmachine/safe", "type": "phpstan-extension", @@ -11,8 +12,8 @@ ], "require": { "php": "^8.1", - "phpstan/phpstan": "^2.1.11", - "thecodingmachine/safe": "^1.2 || ^2.0 || ^3.0", + "phpstan/phpstan": "^2.1.30", + "thecodingmachine/safe": "^3.1", "nikic/php-parser": "^5" }, "require-dev": { @@ -31,7 +32,7 @@ } }, "scripts": { - "phpstan": "phpstan analyse -c phpstan.neon --no-progress -vvv", + "phpstan": "phpstan analyse -c phpstan.neon --no-progress -vv", "test": "XDEBUG_MODE=coverage phpunit", "cs-fix": "phpcbf", "cs-check": "phpcs" diff --git a/phpstan.neon b/phpstan.neon index faf698f..5737c62 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,19 +7,20 @@ parameters: - tests/Rules/UseSafeCallablesRule - tests/Rules/UseSafeClassesRule - tests/Rules/UseSafeFunctionsRule + - tests/Type/Php/data ignoreErrors: - message: '#^Implementing PHPStan\\Rules\\IdentifierRuleError is not covered by backward compatibility promise\. The interface might change in a minor PHPStan version\.$#' identifier: phpstanApi.interface count: 1 path: src/Rules/Error/SafeRuleError.php - + - message: '#^Implementing PHPStan\\Rules\\LineRuleError is not covered by backward compatibility promise\. The interface might change in a minor PHPStan version\.$#' identifier: phpstanApi.interface count: 1 path: src/Rules/Error/SafeRuleError.php - + - message: '#^Implementing PHPStan\\Rules\\RuleError is not covered by backward compatibility promise\. The interface might change in a minor PHPStan version\.$#' identifier: phpstanApi.interface diff --git a/tests/Type/Php/TypeAssertionsTest.php b/tests/Type/Php/TypeAssertionsTest.php index e87b6fc..556436b 100644 --- a/tests/Type/Php/TypeAssertionsTest.php +++ b/tests/Type/Php/TypeAssertionsTest.php @@ -15,7 +15,6 @@ public static function dataFileAsserts(): iterable yield from self::gatherAssertTypes(__DIR__ . '/data/preg_match_checked.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/preg_replace_return.php'); yield from self::gatherAssertTypes(__DIR__ . '/data/json_decode_return.php'); - yield from self::gatherAssertTypes(__DIR__ . '/data/preg_match_identity_check.php'); } /** @@ -29,6 +28,34 @@ public function testFileAsserts( $this->assertFileAsserts($assertType, $file, ...$args); } + /** + * @return iterable + */ + public static function dataKnownProblems(): iterable + { + yield from self::gatherAssertTypes(__DIR__ . '/data/preg_match_identity_check.php'); + } + + /** + * @dataProvider dataKnownProblems + */ + public function testKnownProblems( + string $assertType, + string $file, + mixed ...$args + ): void { + try { + $this->assertFileAsserts($assertType, $file, ...$args); + $this->fail( + "Expected an assertion failure in $file, but it passed. ". + "This is a known issue that should be fixed, but the test ". + "should not fail until then." + ); + } catch (\PHPUnit\Framework\ExpectationFailedException $e) { + $this->assertStringContainsString('Failed asserting that', $e->getMessage(), "Expected an assertion failure in $file, but got a different error: " . $e->getMessage()); + } + } + public static function getAdditionalConfigFiles(): array { return [__DIR__ . '/../../../phpstan-safe-rule.neon']; diff --git a/tests/Type/Php/data/json_decode_return.php b/tests/Type/Php/data/json_decode_return.php index f6c681a..706e9bd 100644 --- a/tests/Type/Php/data/json_decode_return.php +++ b/tests/Type/Php/data/json_decode_return.php @@ -1,4 +1,7 @@