phpyh/psalm-tester
最新稳定版本:0.1.0
Composer 安装命令:
composer require --dev phpyh/psalm-tester
包简介
Test Psalm via phpt files!
README 文档
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-- ...
统计信息
- 总下载量: 9.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-24