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
Psalm Tester

Psalm Tester Laravel Package

phpyh/psalm-tester

Run Psalm assertions from .phpt files. Write phpt tests with --FILE-- and --EXPECT/EXPECTF-- for traces and errors, then execute them via a PHPUnit test suite using PsalmTester. Supports per-suite default Psalm args and per-test --ARGS-- overrides.

View on GitHub
Deep Wiki
Context7

Test Psalm via phpt files!

Frequently asked questions about Psalm Tester
How do I integrate Psalm static analysis into Laravel’s PHPUnit/Pest test suite?
Use `phpyh/psalm-tester` to write `.phpt` files with `--FILE--` and `--EXPECT--` sections, then run them via PHPUnit. For example, create a test class extending `TestCase` and use `PsalmTester::test()` with `StaticAnalysisTest::fromPhptFile()`. This works alongside Laravel’s existing test ecosystem.
Does this package support Laravel-specific Psalm configurations (e.g., Facade stubs)?
The package is agnostic to Laravel-specific configurations but can integrate with plugins like `psalm-plugin-laravel`. You’ll need to manually configure Psalm’s `psalm.json` or use `--ARGS--` in `.phpt` files to include Laravel-specific rules. No built-in Laravel support exists yet.
Can I run Psalm tests in CI/CD pipelines without manual baseline updates?
Yes, use `assertErrorsMatchBaseline()` to compare Psalm output against a stored baseline. This reduces manual intervention in CI/CD, though you may still need occasional updates if Psalm’s error messages change (e.g., new rule versions).
What Laravel versions and Psalm versions does this package support?
The package works with any Laravel version (as it’s framework-agnostic) but requires Psalm 4.x or 5.x. Psalm 6.x support is untested and may require updates. Ensure your `composer.json` aligns with your Psalm version constraints.
How do I customize Psalm arguments for specific tests or globally?
Set default arguments via `PsalmTester::create(defaultArguments: '--config=my_config.xml')`. Override per-test using `--ARGS--` in `.phpt` files. This flexibility lets you target specific Psalm rules or configurations without modifying the global setup.
Will this slow down my CI pipeline significantly?
Running Psalm in tests adds ~5–15 seconds per run, depending on codebase size. Mitigate this by caching results or running tests in parallel (though parallelization isn’t supported in the initial release). For large projects, consider running Psalm separately in CI.
How do I handle false positives in Psalm tests for Laravel’s dynamic features (e.g., Facades)?
Use `--ARGS--` to include Laravel-specific Psalm plugins (e.g., `psalm-plugin-laravel`) or suppress errors via `@psalm-suppress` in code. The baseline comparison feature helps track regressions, but manual tuning may still be needed for complex Laravel patterns.
Can I integrate this with Laravel Forge/Envoyer for deployment-time validation?
Yes, use Artisan commands (e.g., `php artisan psalm:test`) or test events to run Psalm checks before deployments. The package’s CLI-friendly design makes it easy to hook into Forge/Envoyer scripts for pre-deployment validation.
Are there alternatives to `phpyh/psalm-tester` for Psalm in Laravel?
Alternatives include running Psalm directly via `php vendor/bin/psalm` or using `roave/security-advisories` for dependency checks. However, `phpyh/psalm-tester` uniquely integrates Psalm assertions into PHPUnit/Pest, making it ideal for test-driven workflows in Laravel.
How do I update the baseline if Psalm’s error messages change?
Manually update the baseline by re-running tests with `--update-baseline` (if supported) or by editing the stored baseline file. The package doesn’t yet automate baseline syncing, so this requires developer intervention when Psalm’s rules or messages evolve.
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