Getting started
Installation
Require PHPat with Composer:
Activate the extension using one of the following methods:
Configuration
You will need to register your test classes in your PHPStan configuration:
⚠️ Your architecture tests folder should be included in the PHPStan analysed paths.You can configure some PHPat options as follows:
See the complete list of options in the Configuration section.
Test definition
There are different Selectors available to select the classes involved in a rule, and a wide set of Assertions.
Here's an example test with a rule:
<?php
use PHPat\Selector\Selector;
use PHPat\Test\Builder\Rule;
use PHPat\Test\PHPat;
use App\Domain\SuperForbiddenClass;
final 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)
)
->because('this will break our architecture, implement it another way! see /docs/howto.md');
}
}
Usage
Run PHPStan as usual: