All Projects → carlosas → Phpat

carlosas / Phpat

Licence: mit
PHP Architecture Tester - Easy to use architectural testing tool for PHP ✔️

Projects that are alternatives of or similar to Phpat

Wala
T.J. Watson Libraries for Analysis
Stars: ✭ 395 (-19.22%)
Mutual labels:  static-analysis
Phpmnd
PHP Magic Number Detector
Stars: ✭ 431 (-11.86%)
Mutual labels:  static-analysis
Sonar Dotnet
Code analyzer for C# and VB.NET projects https://redirect.sonarsource.com/plugins/vbnet.html
Stars: ✭ 466 (-4.7%)
Mutual labels:  static-analysis
Go Ruleguard
Define and run pattern-based custom linting rules.
Stars: ✭ 402 (-17.79%)
Mutual labels:  static-analysis
Prealloc
prealloc is a Go static analysis tool to find slice declarations that could potentially be preallocated.
Stars: ✭ 419 (-14.31%)
Mutual labels:  static-analysis
Backwardcompatibilitycheck
🆎 Tool to compare two revisions of a class API to check for BC breaks
Stars: ✭ 440 (-10.02%)
Mutual labels:  static-analysis
Applicationinspector
A source code analyzer built for surfacing features of interest and other characteristics to answer the question 'What's in the code?' quickly using static analysis with a json based rules engine. Ideal for scanning components before use or detecting feature level changes.
Stars: ✭ 3,873 (+692.02%)
Mutual labels:  static-analysis
Sark
IDAPython Made Easy
Stars: ✭ 477 (-2.45%)
Mutual labels:  static-analysis
Psalm
A static analysis tool for finding errors in PHP applications
Stars: ✭ 4,523 (+824.95%)
Mutual labels:  static-analysis
Eslint Plugin Sonarjs
SonarJS rules for ESLint
Stars: ✭ 458 (-6.34%)
Mutual labels:  static-analysis
Binee
Binee: binary emulation environment
Stars: ✭ 408 (-16.56%)
Mutual labels:  static-analysis
Saferwall
A hackable malware sandbox for the 21st Century
Stars: ✭ 419 (-14.31%)
Mutual labels:  static-analysis
Salus
Security scanner coordinator
Stars: ✭ 441 (-9.82%)
Mutual labels:  static-analysis
Huskyci
Performing security tests inside your CI
Stars: ✭ 398 (-18.61%)
Mutual labels:  static-analysis
Flowdroid
FlowDroid Static Data Flow Tracker
Stars: ✭ 471 (-3.68%)
Mutual labels:  static-analysis
Credo
A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
Stars: ✭ 4,144 (+747.44%)
Mutual labels:  static-analysis
Gosec
Golang security checker
Stars: ✭ 5,694 (+1064.42%)
Mutual labels:  static-analysis
Elsa
Emacs Lisp Static Analyzer
Stars: ✭ 485 (-0.82%)
Mutual labels:  static-analysis
Dogma
🔐 A code style linter for Elixir
Stars: ✭ 472 (-3.48%)
Mutual labels:  static-analysis
Awesome Linters
A community-driven list of awesome linters.
Stars: ✭ 439 (-10.22%)
Mutual labels:  static-analysis

PHP Architecture Tester

Easy to use architecture testing tool for PHP

Version PHP Version Contributions welcome


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 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
src:
  path: src/
tests:
  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 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\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
            ->classesThat(Selector::haveClassName('App\Domain\*'))
            ->excludingClassesThat(Selector::implementInterface(BlackMagicInterface::class))
            ->canOnlyDependOn()
            ->classesThat(Selector::havePath('Domain/*'))
            ->andClassesThat(Selector::haveClassName('App\Application\Shared\Service\KnownBadApproach'))
            ->build();
    }
    
    public function testAllHandlersExtendAbstractCommandHandler(): Rule
    {
        return $this->newRule
            ->classesThat(Selector::havePath('Application/*/UseCase/*Handler.php'))
            ->excludingClassesThat(Selector::extendClass('App\Application\Shared\UseCase\DifferentHandler'))
            ->andExcludingClassesThat(Selector::includeTrait('App\Legacy\LegacyTrait'))
            ->andExcludingClassesThat(Selector::haveClassName(\App\Application\Shared\UseCase\AbstractCommandHandler::class))
            ->mustExtend()
            ->classesThat(Selector::haveClassName('App\Application\Shared\UseCase\AbstractCommandHandler'))
            ->build();
    }
}
YAML / XML test definition

You can also define tests whether in YAML or XML.

rules:
  testAssertionsImplementAssertionInterface:
    - 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"
       xsi:schemaLocation="https://raw.githubusercontent.com/carlosas/phpat/master/src/Test/Test.xsd">
    <rule name="testAssertionsDoNotDependOnVendors">
        <classes>
            <selector type="havePath">Rule/Assertion/*</selector>
        </classes>
        <assert>canOnlyDependOn</assert>
        <classes>
            <selector type="haveClassName">PhpAT\*</selector>
            <selector type="haveClassName">Psr\*</selector>
        </classes>
    </rule>
</test>

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].