phpyh / psalm-tester
Test Psalm via phpt files!
Installs: 5 393
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 2
Requires
- php: ^8.1
- composer-runtime-api: ^2.1
- phpunit/phpunit: ^9 || ^10
Requires (Dev)
- ergebnis/composer-normalize: ^2.41.1
- friendsofphp/php-cs-fixer: ^3.48.0
- icanhazstring/composer-unused: ^0.8.11
- maglnet/composer-require-checker: ^4.7.1
- phpyh/coding-standard: ^2.6.0
- psalm/plugin-phpunit: ^0.18.4
- rector/rector: ^0.19.2
- vimeo/psalm: ^5.20.0
README
Test Psalm via phpt files!
Installation
composer require --dev phpyh/psalm-tester
Basic usage
1. Write a test in phpt format
tests/array_values.phpt
--FILE-- <?php /** @psalm-trace $_list */ $_list = array_values(['a' => 1, 'b' => 2]); --EXPECT-- Trace on line 9: $_list: non-empty-list<1|2>
To avoid hardcoding error details, you can use EXPECTF
:
--EXPECTF-- Trace on line %d: $_list: non-empty-list<%s>
2. Add a test suite
tests/PsalmTest.php
<?php use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use PHPyh\PsalmTester\PsalmTester; use PHPyh\PsalmTester\StaticAnalysisTest; final class PsalmTest extends TestCase { private ?PsalmTester $psalmTester = null; #[TestWith([__DIR__ . '/array_values.phpt'])] public function testPhptFiles(string $phptFile): void { $this->psalmTester ??= PsalmTester::create(); $this->psalmTester->test(StaticAnalysisTest::fromPhptFile($phptFile)); } }
Passing different arguments to Psalm
By default PsalmTester
runs Psalm with --no-progress --no-diff --config=
psalm.xml.
You can change this at the PsalmTester
level:
use PHPyh\PsalmTester\PsalmTester; PsalmTester::create( defaultArguments: '--no-progress --no-cache --config=my_default_config.xml', );
or for each test individually using --ARGS--
section:
--ARGS-- --no-progress --config=my_special_config.xml --FILE-- ... --EXPECT-- ...