Popularity
5.5
Growing
Activity
6.1
Declining
791
18
27

Monthly Downloads: 0
Programming language: PHP
License: MIT License
Latest version: v0.10.0

PHP Architecture Tester alternatives and similar libraries

Based on the "Static Analysis" category.
Alternatively, view PHP Architecture Tester alternatives based on common mentions on social networks and blogs.

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

Add another 'Static Analysis' Library

README

Easy to use architecture testing tool for PHP

ℹī¸ PHPat has been converted into a PHPStan extension. Read the [UPGRADE notes](doc/UPGRADE-0.10.md)! 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](doc/WHAT_TO_TEST.md) 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

⚠ī¸ Your architecture tests folder should be included in the PHPStan analysed paths. See [PHPat's own PHPat configuration](ci/phpstan-phpat.neon) as an example.

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](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:

<?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

⚠ 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 open source, contributions are welcome. Please have a look to the [Contribution docs](.github/CONTRIBUTING.md).