Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpstan Dev Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

  1. composer require --dev shipmonk/phpstan-dev
  2. Create a test class extending \ShipMonk\PHPStanDev\RuleTestCase
  3. Write a fixture file (e.g., Data/code.php) with code and // error: Message comments
  4. Call $this->analyzeFiles([__DIR__ . '/Data/code.php']) in your test method

Example fixture:

<?php

$valid = 'No error here';
$invalid = forbidden(); // error: Call to forbidden function

Implementation Patterns

  • Fixture-driven testing: Keep fixtures minimal, readable, and co-located with tests. Use // error: Message comments to assert what errors are expected — not where or how many.
  • Autofix workflow: Run $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.
  • Cross-file support: Include multiple files and traits in $this->analyzeFiles([...]) — the framework automatically detects errors across files and traits (v0.1.2+).
  • Multi-error lines: Emit multiple errors per line using // error: msg1 // error: msg2. Since v0.1.6, comment order no longer matters — only existence and message match.

Gotchas and Tips

  • 🔥 Autofix peril: Leaving 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.
  • Message matching: Comments use substring matching — avoid overly generic messages. Partial strings (e.g., // error: forbidden) work but risk false positives if multiple rules exist.
  • Trait pitfalls: Ensure traits are included in analyzed files; missing traits cause silent failures with no errors reported. Use __DIR__ . '/Data/Traits/MyTrait.php' explicitly.
  • Windows paths: Normalize paths aggressively — use __DIR__-relative paths and avoid ./... v0.1.2 fixed path normalization, but relative paths still trip up on mixed-drive setups.
  • Extensibility: Extend RuleTestCase in your own TestCase base class to add reusable helpers (e.g., assertRuleOutput($code, $expectedErrors)). The base class is intentionally thin and mockable.
  • Debugging: Enable --debug mode (via PHPStan’s console) when tests fail unexpectedly — it shows actual vs expected error locations and messages.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport