j6s / phpat

PHP Architecture Tester - Easy to use architecture testing tool for PHP :heavy_check_mark:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logo

Easy to use architecture testing tool for PHP

Packagist Minimum PHP MIT license Contributions welcome Hits


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

⚠ Launching early stage releases (0.x.x) with a different SemVer strategy. We are using minor for breaking changes. This will change to strict SemVer with the release of 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.

About

PHP Architecture Tester - Easy to use architecture testing tool for PHP :heavy_check_mark:

License:MIT License


Languages

Language:PHP 100.0%