Giter Club home page Giter Club logo

phpat's Introduction

PHP Architecture Tester

Easy to use architecture testing tool for PHP

Version PHP Version PHPStan Version Contributions welcome


โ„น๏ธ PHPat has been converted into a PHPStan extension. Read the UPGRADE notes!
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 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 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 to choose which classes will intervene in a rule and a wide range of Assertions.

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.

phpat's People

Contributors

akondas avatar carlosas avatar dabrowiecki avatar faguaron avatar hkdobrev avatar irozgar avatar j6s avatar jakobw avatar jmartin82 avatar localheinz avatar maciejkosiarski avatar marmichalski avatar nreynis avatar p810 avatar rvanlaak avatar staabm avatar szepeviktor avatar tigitz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.