Monthly Downloads: 11,885
Programming language: PHP
License: MIT License
Latest version: v0.7.4

PHP Architecture Tester alternatives and similar libraries

Based on the "Static Analysis" category

Do you think we are missing an alternative of PHP Architecture Tester or a related project?

Add another 'Static Analysis' Library


Easy to use architecture testing tool for PHP

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. You can also integrate phpat easily into your toolchain.

There are four groups of supported assertions: Dependency, Inheritance, Composition and Mixin.

โ„น๏ธ Check out the section [WHAT TO TEST](doc/WHAT_TO_TEST.md) to see some examples of typical use cases.

Installation ๐Ÿ’ฝ

Just require phpat with Composer:

composer require --dev phpat/phpat

Manual download

If you have dependency conflicts, you can also download the latest PHAR file from Releases.

You will have to use it executing php phpat.phar phpat.yaml and declare your tests in XML or YAML.

Configuration ๐Ÿ”ง

You might want to setup a basic configuration:

# phpat.yaml
  path: src/
  path: tests/architecture/

Complete list of options

Name Description Default
src path The root path of your application no default
src include Files you want to be tested excluding the rest all files
src exclude Files you want to be excluded in the tests no files
composer $ALIAS json Path of your composer.json file (multiple) no files
composer $ALIAS lock Path of your composer.lock file (multiple) no files
tests path The path where your tests are no default
options verbosity Output verbosity level (0/1/2) 1
options dry-run Report failed suite without error exit code (T/F) false
options ignore_docblocks Ignore relations on docblocks (T/F) false
options ignore_php_extensions Ignore relations to core and extensions classes (T/F) true

Test definition ๐Ÿ““

There are different [Selectors](doc/SELECTORS.md) to choose which classes will intervene in a rule and a wide range of [Assertions](doc/ASSERTIONS.md).

This could be a test with a couple of rules:


use PhpAT\Rule\Rule;
use PhpAT\Selector\Selector;
use PhpAT\Test\ArchitectureTest;
use App\Domain\BlackMagicInterface;

class ExampleTest extends ArchitectureTest
    public function testDomainDoesNotDependOnOtherLayers(): Rule
        return $this->newRule

    public function testAllHandlersExtendAbstractCommandHandler(): Rule
        return $this->newRule

YAML / XML test definition

You can also define tests whether in YAML or XML.

    - classes:
        - havePath: Rule/Assertion/*
    - excluding:
        - haveClassName: PhpAT\Rule\Assertion\*\MustNot*
        - havePath: Rule/Assertion/MatchResult.php
    - assert: mustExtend
    - classes:
        - haveClassName: PhpAT\Rule\Assertion\AbstractAssertion
<?xml version="1.0" encoding="UTF-8" ?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <rule name="testAssertionsDoNotDependOnVendors">
            <selector type="havePath">Rule/Assertion/*</selector>
            <selector type="haveClassName">PhpAT\*</selector>
            <selector type="haveClassName">Psr\*</selector>

Usage ๐Ÿš€

Run the bin with your configuration file:

vendor/bin/phpat phpat.yaml

โš  Launching early stage releases (0.x.x) could break the API according to Semantic Versioning 2.0. We are using minor for breaking changes. This will change with the release of the stable 1.0.0 version.

PHP Architecture Tester is in a very early stage, contributions are welcome. Please have a look to the [Contribution docs](.github/CONTRIBUTING.md).