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
7 changes: 4 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

on:
pull_request: ~
pull_request:
push:
branches:
- master
Expand All @@ -19,6 +19,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
dependencies:
- "highest"
include:
Expand All @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out these older versions have been broken forever...

"nikic/php-parser": "^5"
},
"require-dev": {
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion tests/Type/Php/TypeAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -29,6 +28,34 @@ public function testFileAsserts(
$this->assertFileAsserts($assertType, $file, ...$args);
}

/**
* @return iterable<mixed>
*/
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'];
Expand Down
3 changes: 3 additions & 0 deletions tests/Type/Php/data/json_decode_return.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace TheCodingMachine\Safe\PHPStan\Type\Php\data;

$value = \Safe\json_decode('null');
\PHPStan\Testing\assertType('null', $value);

Expand Down
Loading