boundwize/pyrameter
Composer 安装命令:
composer require boundwize/pyrameter
包简介
PHPUnit extension that measures the shape of your test pyramid.
README 文档
README
Pyrameter is a PHPUnit extension that measures the shape of your test suite.
It classifies tests as unit, functional, integration, or e2e based on what the test files consume, then reports whether your suite still matches your expected test pyramid.
Pyrameter does not trust test directories.
It does not assume infrastructure classes are always integration tests.
It does not scan production classes.
Instead, it looks for configured heavy usage in test files:
- no heavy usage => unit
- framework test runtime => functional
- database or external system usage => integration
- browser driver usage => e2e
vendor/bin/phpunit ........................ Pyrameter ========= Shape: Integration Mountain Result: Violated ⚠ Kind Tests Actual Target Status Unit 39 65.0% >= 70.0% ✗ Functional 10 16.7% <= 20.0% ✓ Integration 9 15.0% <= 8.0% ✗ E2E 1 1.7% <= 2.0% ✓ Unknown 1 1.7% <= 2.0% ✓ Total: 60 tests Your suite is getting heavier.
Installation
composer require --dev boundwize/pyrameter
Register PHPUnit extension
<extensions> <bootstrap class="Pyrameter\Extension"> <parameter name="config" value="pyrameter.php"/> </bootstrap> </extensions>
If the config parameter is omitted, Pyrameter looks for pyrameter.php in the current working directory. If the file does not exist, Pyrameter uses its default configuration.
Configure
Create pyrameter.php. You can start from Pyrameter's built-in configuration with defaults(), or build a configuration from scratch with create().
Use defaults() when you want the same baseline Pyrameter uses when no config file exists: common usage rules for PDO, mysqli, Doctrine, Redis, Symfony functional tests, Panther, and WebDriver, plus the default target shape.
<?php declare(strict_types=1); use Pyrameter\Config\PyrameterConfig; use Pyrameter\TestKind; return PyrameterConfig::defaults() ->usesNamespace('App\Tests\Browser\\', TestKind::E2E) ->targetShape( unit: ['min' => 75], functional: ['max' => 15], integration: ['max' => 7], e2e: ['max' => 2], unknown: ['max' => 1], );
Use create() when you want full control. It starts with no usage rules and no target shape, so add every rule and target your project should use:
<?php declare(strict_types=1); use Pyrameter\Config\PyrameterConfig; use Pyrameter\TestKind; return PyrameterConfig::create() ->usesClass(PDO::class, TestKind::Integration) ->usesNamespace('Doctrine\DBAL\\', TestKind::Integration) ->usesNamespace('Symfony\Bundle\FrameworkBundle\Test\\', TestKind::Functional) ->usesNamespace('Symfony\Component\Panther\\', TestKind::E2E) ->usesNamespace('Facebook\WebDriver\\', TestKind::E2E) ->targetShape( unit: ['min' => 70], functional: ['max' => 18], integration: ['max' => 8], e2e: ['max' => 2], unknown: ['max' => 2], );
Each target is a percentage range. Missing min means 0; missing max means 100. When targetShape() is called, missing kinds default to ['min' => 0, 'max' => 100], which Pyrameter reports as no target.
By default, Pyrameter is report-only: it prints target violations but does not change PHPUnit's exit code.
To fail the PHPUnit process after a target violation:
return PyrameterConfig::defaults() ->failOnViolation();
Pyrameter classifies tests by static usage rules in test files. It measures suite shape; it does not prove perfect test taxonomy.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-14
