Installation Add to your Laravel project via Composer:
composer require --dev boundwize/pyrameter
Ensure PHPUnit is installed (phpunit/phpunit in require-dev).
First Run Execute tests normally:
vendor/bin/phpunit
Pyrameter will automatically analyze your test suite and display a shape report.
Initial Use Case
Where to Look First
Unit/, Integration/, Feature/).Shape: and Result: lines in the terminal. Example:
Shape: Unit Pyramid ✓
Result: Compliant ✅
phpunit.xml for custom test suite paths or exclusions.CI/CD Pipeline Add Pyrameter to your CI workflow (e.g., GitHub Actions) to enforce test pyramid compliance:
- name: Run PHPUnit with Pyrameter
run: vendor/bin/phpunit --testdox-html=report.html
Fail the build if the shape is "Violated" (customize via config).
Test Suite Organization
tests/
├── Unit/ # Unit tests (base of pyramid)
├── Integration/ # Integration tests (middle)
└── Feature/ # E2E/Feature tests (apex)
@group unit, @group integration, etc., for dynamic grouping.Dynamic Configuration
Override default behavior in phpunit.xml:
<phpunit>
<extensions>
<extension class="Boundwize\Pyrameter\Extension">
<arguments>
<argument name="unitPath" value="tests/Unit"/>
<argument name="integrationPath" value="tests/Integration"/>
<argument name="e2ePath" value="tests/Feature"/>
<argument name="threshold">
<array>
<element><unit>70</unit></element>
<element><integration>20</integration></element>
<element><e2e>10</e2e></element>
</array>
</argument>
</arguments>
</extension>
</extensions>
</phpunit>
Laravel-Specific Patterns
// app/Console/Commands/TestPyramidCommand.php
use Boundwize\Pyrameter\Pyrameter;
class TestPyramidCommand extends Command {
protected $signature = 'test:pyramid';
protected $description = 'Display test pyramid shape';
public function handle(Pyrameter $pyrameter) {
$shape = $pyrameter->analyze();
$this->line($shape->toAsciiArt());
}
}
// app/Providers/AppServiceProvider.php
public function register() {
$this->app->bind(Pyrameter::class, function () {
return new Pyrameter(
config('pyrameter.unit_path'),
config('pyrameter.integration_path'),
config('pyrameter.e2e_path')
);
});
}
False Positives/Negatives
tests/Unit/User/ vs. tests/Unit/).--debug flag to see raw test classification:
vendor/bin/phpunit --debug --extensions=Boundwize\Pyrameter\Extension
Threshold Sensitivity
phpunit.xml or config. Example:
<argument name="threshold">
<array>
<element><unit>50</unit></element>
<element><integration>30</integration></element>
<element><e2e>20</e2e></element>
</array>
</argument>
Performance Overhead
Test Naming Conflicts
UserTest.php in Unit/ and Integration/) may cause confusion.UserUnitTest.php, UserIntegrationTest.php) or clear naming conventions.Verbose Output Enable debug mode to see detailed classification:
vendor/bin/phpunit -d pyrameter.debug=1
Output will include:
[Pyrameter] Classified 150 tests:
- Unit: 105 (70%)
- Integration: 30 (20%)
- E2E: 15 (10%)
Custom Exclusions Exclude specific tests or directories from analysis:
<extension class="Boundwize\Pyrameter\Extension">
<arguments>
<argument name="excludedPaths" value="tests/Unit/SlowTests"/>
</arguments>
</extension>
Custom Shapes Extend Pyrameter to support additional shapes (e.g., "Inverted Pyramid" for API-heavy apps):
// app/Extensions/CustomPyrameter.php
use Boundwize\Pyrameter\Pyrameter;
class CustomPyrameter extends Pyrameter {
public function analyze(): Shape {
$shape = parent::analyze();
if ($shape->getE2ePercentage() > $shape->getUnitPercentage()) {
return new InvertedPyramid($shape->getCounts());
}
return $shape;
}
}
Register in phpunit.xml:
<extension class="App\Extensions\CustomPyrameter"/>
Visualization Integrate with tools like:
spatie/laravel-dashboard).Git Hooks Enforce pyramid rules pre-commit:
composer require --dev phpunit/phpunit
vendor/bin/phpunit --fail-on-pyrameter-violation
Add to .git/hooks/pre-commit:
#!/bin/sh
vendor/bin/phpunit --fail-on-pyrameter-violation || exit 1
Case Sensitivity
Paths in phpunit.xml are case-sensitive on Linux/macOS but not on Windows. Use absolute paths or normalize:
<argument name="unitPath" value="./tests/Unit"/>
PHPUnit Version
composer require boundwize/pyrameter:^1.0 --dev
Parallel Testing
Pyrameter may not work correctly with --parallel due to test classification logic. Use sequential runs for analysis:
vendor/bin/phpunit --group=unit --group=integration --group=e2e
How can I help you explore Laravel packages today?