Easy to use architecture testing tool for PHP
The standalone version (v0.9) will still be available and receive critical bugfixes if needed.
๐
Introduction PHP Architecture Tester is a static analysis tool to verify architectural requirements.
It provides a natural language abstraction to define your own architectural rules and test them against your software.
Check out the section WHAT TO TEST to see some examples of typical use cases.
๐ฝ
Installation Require PHPat with Composer:
composer require --dev phpat/phpat
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use phpstan/extension-installer
, enable the extension in your PHPStan configuration:
# phpstan.neon
includes:
- vendor/phpat/phpat/extension.neon
๐ง
Configuration You will need to register your test classes in your PHPStan configuration:
# phpstan.neon
services:
-
class: Tests\Architecture\MyFirstTest
tags:
- phpat.test
-
class: Tests\Architecture\MySecondTest
tags:
- phpat.test
You can also configure some PHPat options, for instance:
# phpstan.neon
parameters:
phpat:
ignore_doc_comments: true
Complete list of options
Name | Description | Default |
---|---|---|
ignore_doc_comments |
Ignore relations on Doc Comments | false |
๐
Test definition There are different Selectors to choose which classes will intervene in a rule and a wide range of Assertions.
This could be a test with a couple of rules:
<?php
use PHPat\Selector\Selector;
use PHPat\Test\Builder\Rule;
use PHPat\Test\PHPat;
use App\Domain\SuperForbiddenClass;
class MyFirstTest
{
public function test_domain_does_not_depend_on_other_layers(): Rule
{
return PHPat::rule()
->classes(Selector::namespace('App\Domain'))
->shouldNotDependOn()
->classes(
Selector::namespace('App\Application'),
Selector::namespace('App\Infrastructure'),
Selector::classname(SuperForbiddenClass::class),
Selector::classname('/^SomeVendor\\\.*\\\ForbiddenSubfolder\\\.*/', true)
);
}
}
๐
Usage Run PHPStan as usual:
php vendor/bin/phpstan analyse -c phpstan.neon
1.0.0
version.
PHP Architecture Tester is open source, contributions are welcome. Please have a look to the Contribution docs.