Easy to use architecture testing tool for PHP
π
Introduction PHP Architecture Tester is a tool that helps you keep your project architecture clean.
It provides a natural language abstraction to define your own architecture rules and test them against your software. You can also integrate phpat easily into your toolchain.
Current supported relations:
- Dependency: SomeClass depends (or not) on AnotherClass
- Inheritance: SomeClass extends (or not) AnotherClass
- Composition: SomeClass implements (or not) SomeInterface
- Mixin: SomeClass includes (or not) SomeTrait
π½
Installation Just require phpat with Composer:
composer require --dev carlosas/phpat
π§
Configuration You might want to setup a basic configuration:
# phpat.yml
src:
path: src/
tests:
path: tests/architecture/
This is the complete list of options:
src
path
: The root path of your application.src
include
: Files you want to be tested excluding the rest (default=all).src
exclude
: Files you want to be excluded in the tests (default=none).tests
path
: The path where your tests are.options
verbosity
: 0/1/2 output verbosity level (default=1).
π
Test definition This could be a test with a couple of rules:
<?php
use PhpAT\Rule\Rule;
use PhpAT\Selector\Selector;
use PhpAT\Test\ArchitectureTest;
class ExampleTest extends ArchitectureTest
{
public function testDomainDoesNotDependOnOtherLayers(): Rule
{
return $this->newRule
->classesThat(Selector::havePath('Domain/*'))
->mustNotDependOn()
->classesThat(Selector::havePath('Application/*'))
->andClassesThat(Selector::havePath('Infrastructure/*'))
->andClassesThat(Selector::havePath('Presentation/*'))
->excludingClassesThat(Selector::havePath('Application/Shared/Service/KnownBadApproach.php'))
->build();
}
public function testAllHandlersExtendAbstractCommandHandler(): Rule
{
return $this->newRule
->classesThat(Selector::havePath('Application/*/UseCase/*Handler.php'))
->excludingClassesThat(Selector::havePath('Application/Shared/UseCase/Different*Handler.php'))
->andExcludingClassesThat(Selector::havePath('Application/Shared/UseCase/AbstractCommandHandler.php'))
->mustExtend()
->classesThat(Selector::havePath('Application/Shared/UseCase/AbstractCommandHandler.php'))
->build();
}
}
π
Usage Run the bin with your configuration file:
vendor/bin/phpat phpat.yml
1.0.0
. See Semantic Versioning.
PHP Architecture Tester is in a very early stage, contributions are welcome. Please take a look to the Contribution docs.