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

Plugin Phpunit Laravel Package

psalm/plugin-phpunit

Psalm plugin that teaches Psalm about PHPUnit tests. Adds better type inference and assertions for PHPUnit APIs so your test suite is analyzed more accurately. Requires Psalm v4+. Install via Composer and enable with psalm-plugin.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Enhanced Test Reliability for Laravel Applications

    • Shift-Left Quality: Integrate Psalm’s static analysis into PHPUnit tests to catch type-related issues (e.g., incorrect assertions, mismatched return types) before test execution, reducing flaky tests and CI/CD failures.
    • Build vs. Buy Decision: Avoid reinventing custom test validation tools (e.g., regex-based checks) by leveraging Psalm’s mature static analysis engine, which is actively maintained and optimized for PHP/Laravel ecosystems.
  • Roadmap Priorities

    • Type Safety for Critical Paths: Mandate Psalm + PHPUnit plugin adoption for new Laravel features (e.g., custom validation rules, event listeners) where type errors could lead to production incidents.
    • Legacy Code Modernization: Prioritize high-risk test suites (e.g., monolithic controllers, complex business logic tests) for incremental static analysis adoption to improve maintainability.
    • CI/CD Optimization: Fail builds on test-related type errors (e.g., invalid #[Test] attributes, data provider mismatches) to catch issues early, reducing false positives in test reports.
  • Key Use Cases

    • API Contract Validation: Ensure test assertions match Laravel API responses (e.g., JsonResponse types) to prevent runtime serialization errors.
    • Database Interaction Safety: Catch Eloquent query mismatches (e.g., asserting Collection when a query returns Builder) before tests execute.
    • Dependency Injection Testing: Validate that service container bindings are correctly typed in tests (e.g., bind(MyService::class) resolves to the right interface).
    • Modern PHPUnit Attributes: Support for PHPUnit 9+ attributes (#[Test], #[DataProvider], #[Before]) aligns with Laravel’s adoption of newer testing patterns.

When to Consider This Package

  • Adopt When:

    • Your Laravel project uses Psalm v4+ for static analysis and PHPUnit 9+ for testing.
    • You experience flaky tests or runtime type errors in critical paths (e.g., payments, authentication, API endpoints).
    • Your team prioritizes developer productivity and wants to reduce manual debugging of test failures.
    • You’re using PHPUnit attributes (#[Test], #[DataProvider]) and need static validation to catch misconfigurations early.
    • Your CI/CD pipeline suffers from noisy test failures due to type mismatches, and you want to fail builds on static analysis errors before execution.
  • Look Elsewhere If:

    • You don’t use Psalm (e.g., relying solely on PHP’s built-in type hints or other tools like PHPStan).
    • Your tests are simple (e.g., basic CRUD operations with no complex types or assertions).
    • Your team lacks tooling discipline (Psalm requires addressing warnings, which may slow down PRs or require buy-in).
    • You need runtime test validation (e.g., mocking HTTP requests, dynamic test data) instead of static checks.
    • You’re using PHPUnit 8 or older (limited attribute support may not justify the effort).

How to Pitch It (Stakeholders)

For Executives: "This plugin dramatically reduces test-related bugs in production by catching type mismatches before they cause failures. For example, it’ll flag if a test incorrectly asserts null for a method returning string|array, saving hours in debugging and reducing incident response time. Low-cost, high-impact: Integrates seamlessly with existing workflows, requires minimal setup, and aligns with Laravel’s focus on reliability. ROI: Fewer production incidents, faster releases, and happier developers—all while maintaining compatibility with your current stack."

For Engineering Teams: *"Psalm’s PHPUnit plugin adds static type checking to your tests, similar to how your IDE highlights syntax errors—but for test logic. Key benefits for Laravel:

  • Faster Debugging: Catch test logic errors early (e.g., assertEquals() with mismatched types, invalid data providers).
  • Consistency: Enforce type safety across tests and production code (e.g., Eloquent models, API responses, service container bindings).
  • Modern PHPUnit Support: Works with #[Test], #[DataProvider], and #[Before] attributes for Laravel’s latest testing stack. Tradeoff: Requires fixing Psalm warnings (but reduces runtime surprises). How to start:
  1. Add to composer.json: composer require --dev psalm/plugin-phpunit.
  2. Enable the plugin: vendor/bin/psalm-plugin enable psalm/plugin-phpunit.
  3. Configure psalm.xml to include test files: <file-list><dir>tests/</dir></file-list>.
  4. Run: ./vendor/bin/psalm --init to generate config. Pro Tip: Use --no-cache in CI to catch new issues immediately. Example: If a test asserts assertSame(1, $user->id), Psalm will verify $user->id is actually an int—saving you from runtime TypeError exceptions."*

For QA/DevOps: *"This reduces CI/CD noise by catching test-related type errors before execution. For example:

  • Data Providers: Validates that @dataProvider methods return iterable types and match test expectations.
  • Assertions: Ensures assertSame(), assertEquals(), and other assertions align with actual return types (e.g., no null vs. int mismatches).
  • Attributes: Catches misconfigured #[Test], #[Before], or #[After] attributes before tests run. Result: Fewer flaky tests, cleaner CI logs, and fewer false positives in test reports. Recommendation: Start by enabling this in a non-critical branch to measure the impact on test failures."*
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity