shipmonk / phpstan-dev
Development utilities for PHPStan rules testing, extracted from shipmonk/phpstan-rules
0.1.6
2026-01-29 15:37 UTC
Requires
- php: ^7.4 || ^8.0
- phpstan/phpstan: ^2.1.8
Requires (Dev)
- ergebnis/composer-normalize: ^2.45.0
- phpstan/phpstan-deprecation-rules: ^2.0.1
- phpstan/phpstan-phpunit: ^2.0.4
- phpstan/phpstan-strict-rules: ^2.0.3
- phpunit/phpunit: ^9.6.22
- shipmonk/coding-standard: ^0.2.0
- shipmonk/composer-dependency-analyser: ^1.8.1
- shipmonk/dead-code-detector: ^0.9.0
- shipmonk/name-collision-detector: ^2.1.1
Suggests
- phpunit/phpunit: ^9.6.22 for running tests that use RuleTestCase
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-23 08:25:31 UTC
README
Inplace fixture asserts and autofix for PHPStan rules. No more manual line adjustments in tests when new code is added to rule fixtures.
Installation
composer require --dev shipmonk/phpstan-dev
Usage
declare(strict_types = 1);
use PHPStan\Rules\Rule;
/**
* @extends RuleTestCase
*/
class YourRuleTest extends \ShipMonk\PHPStanDev\RuleTestCase
{
public function testRule(): void
{
$this->analyzeFiles([__DIR__ . '/Data/code.php']);
}
}
Create test fixture at code.php:
$valid = 'This is valid code';
$invalid = something(); // error: Rule error message
Key Features
In-fixture error asserts of via // error:
Mark expected errors directly in test files via PHP comments:
$validCode = 'No error expected here';
$invalidCode = forbidden(); // error: Rule error message
$alsoInvalid = another(); // error: Rule error message // error: Same-line multi errors
Autofix
Automatically generate inplace error comments during development:
public function testRule(): void { $this->analyzeFiles([...], autofix: true); }
⚠️ Important: Remove autofix: true before committing - tests will fail if autofix is enabled.
Contributing
- Check your code by
composer check - Autofix coding-style by
composer fix:cs - All functionality must be tested
License
MIT