shipmonk/phpstan-dev
Utilities for developing PHPStan rules: write expected errors directly in fixture files using // error: comments and avoid brittle line-number assertions. Includes an autofix mode to generate/update inline error comments during rule development.
Start by installing the package as a dev dependency and extending RuleTestCase in your PHPStan rule tests. The first use case is writing test fixtures with inline // error: comments to declare expected violations — eliminating manual error counting and diff-based assertions.
composer require --dev shipmonk/phpstan-dev\ShipMonk\PHPStanDev\RuleTestCaseData/code.php) with code and // error: Message comments$this->analyzeFiles([__DIR__ . '/Data/code.php']) in your test methodExample fixture:
<?php
$valid = 'No error here';
$invalid = forbidden(); // error: Call to forbidden function
// error: Message comments to assert what errors are expected — not where or how many.$this->analyzeFiles([...], autofix: true) during active rule development to auto-populate or update // error: comments. Crucially, remove autofix: true before committing — tests will fail if enabled in CI.$this->analyzeFiles([...]) — the framework automatically detects errors across files and traits (v0.1.2+).// error: msg1 // error: msg2. Since v0.1.6, comment order no longer matters — only existence and message match.autofix: true in committed tests silently invalidates assertions by rewriting fixture comments. Always run tests without autofix before push; add pre-commit hook to enforce autofix: false.// error: forbidden) work but risk false positives if multiple rules exist.__DIR__ . '/Data/Traits/MyTrait.php' explicitly.__DIR__-relative paths and avoid ./... v0.1.2 fixed path normalization, but relative paths still trip up on mixed-drive setups.RuleTestCase in your own TestCase base class to add reusable helpers (e.g., assertRuleOutput($code, $expectedErrors)). The base class is intentionally thin and mockable.--debug mode (via PHPStan’s console) when tests fail unexpectedly — it shows actual vs expected error locations and messages.How can I help you explore Laravel packages today?