PHPackages                             ta-tikoma/phpunit-architecture-test - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. ta-tikoma/phpunit-architecture-test

ActiveLibrary[Testing &amp; Quality](/categories/testing)

ta-tikoma/phpunit-architecture-test
===================================

Methods for testing application architecture

0.8.7(3mo ago)10745.9M—0.9%12[2 issues](https://github.com/ta-tikoma/phpunit-architecture-test/issues)11MITPHPPHP ^8.1.0CI passing

Since Oct 29Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/ta-tikoma/phpunit-architecture-test)[ Packagist](https://packagist.org/packages/ta-tikoma/phpunit-architecture-test)[ RSS](/packages/ta-tikoma-phpunit-architecture-test/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (34)Used By (11)

PHPUnit Application Architecture Test
=====================================

[](#phpunit-application-architecture-test)

**Idea**: write architecture tests as well as feature and unit tests. Protect your architecture code style!

Example
-------

[](#example)

Don't use repositories in controllers use only in services classes. Take three layers "repositories", "services", "controllers" and add asserts on dependencies.

```
$controllers  = $this->layer()->leaveByNameStart('App\\Controllers');
$services     = $this->layer()->leaveByNameStart('App\\Services');
$repositories = $this->layer()->leaveByNameStart('App\\Repositories');

$this->assertDoesNotDependOn($controllers, $repositories);
$this->assertDependOn($controllers, $services);
$this->assertDependOn($services, $repositories);
```

Installation
------------

[](#installation)

#### Install via composer

[](#install-via-composer)

```
composer require --dev ta-tikoma/phpunit-architecture-test
```

#### Add trait to Test class

[](#add-trait-to-test-class)

```
abstract class TestCase extends BaseTestCase
{
    use ArchitectureAsserts;
}
```

Use
---

[](#use)

- Create test
- Make layers of application
- Add asserts

```
    public function test_make_layer_from_namespace()
    {
        $app = $this->layer()->leaveByNameStart('PHPUnit\\Architecture');
        $tests = $this->layer()->leaveByNameStart('tests');

        $this->assertDoesNotDependOn($app, $tests);
        $this->assertDependOn($tests, $app);
    }
```

#### Run

[](#run)

```
./vendor/bin/phpunit
```

Test files structure
--------------------

[](#test-files-structure)

- tests
    - Architecture
        - SomeTest.php
    - Feature
    - Unit

How to build Layer
------------------

[](#how-to-build-layer)

- `$this->layer()` take access to layer with all objects and filter for create your layer:
    - leave objects in layer only:
        - `->leave($closure)` by closure
        - `->leaveByPathStart($path)` by object path start
        - `->leaveByNameStart($name)` by object name start
        - `->leaveByNameRegex($name)` by object name regex
        - `->leaveByType($name)` by object type
    - remove objects from layer:
        - `->exclude($closure)` by closure
        - `->excludeByPathStart($path)` by object path start
        - `->excludeByNameStart($name)` by object name start
        - `->excludeByNameRegex($name)` by object name regex
        - `->excludeByType($name)` by object type
- you can create multiple layers with split:
    - `->split($closure)` by closure
    - `->splitByNameRegex($closure)` by object name

Asserts
-------

[](#asserts)

### Dependencies

[](#dependencies)

**Example:** Controllers don't use Repositories only via Services

- `assertDependOn($A, $B)` Layer A must contains dependencies by layer B.
- `assertDoesNotDependOn($A, $B)` Layer A (or layers in array A) must not contains dependencies by layer B (or layers in array B).

### Methods

[](#methods)

- `assertIncomingsFrom($A, $B)` Layer A must contains arguments with types from Layer B
- `assertIncomingsNotFrom($A, $B)` Layer A must not contains arguments with types from Layer B
- `assertOutgoingFrom($A, $B)` Layer A must contains methods return types from Layer B
- `assertOutgoingNotFrom($A, $B)` Layer A must not contains methods return types from Layer B
- `assertMethodSizeLessThan($A, $SIZE)` Layer A must not contains methods with size less than SIZE

### Properties

[](#properties)

- `assertHasNotPublicProperties($A)` Objects in Layer A must not contains public properties

### Essence

[](#essence)

You can use `$layer->essence($path)` method for collect data from layer. For example get visibility of all properties in layer: `$visibilities = $layer->essence('properties.*.visibility');` .

- `assertEach($list, $check, $message)` - each item of list must passed tested by $check-function
- `assertNotOne($list, $check, $message)` - not one item of list must not passed tested by $check-function
- `assertAny($list, $check, $message)` - one or more item of list must not passed tested by $check-function

Alternatives
------------

[](#alternatives)

- [Deptrac](https://github.com/qossmic/deptrac)
- [PHP Architecture Tester](https://github.com/carlosas/phpat)
- [PHPArch](https://github.com/j6s/phparch)
- [Arkitect](https://github.com/phparkitect/arkitect)

#### Advantages

[](#advantages)

- Dynamic creation of layers by regular expression (not need declare each module)
- Run along with the rest of tests from [phpunit](https://github.com/sebastianbergmann/phpunit)
- Asserts to method arguments and return types (for check dependent injection)
- Asserts to properties visibility

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity66

Solid adoption and visibility

Community29

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 64.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~193 days

Total

32

Last Release

90d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bf0bc8b0fdacd90ce833f2956df805434b84b1daafa8bbdf1dfdd79ce36b6f2?d=identicon)[ta-tikoma](/maintainers/ta-tikoma)

---

Top Contributors

[![ta-tikoma](https://avatars.githubusercontent.com/u/2934128?v=4)](https://github.com/ta-tikoma "ta-tikoma (88 commits)")[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (40 commits)")[![fabio-ivona](https://avatars.githubusercontent.com/u/8792274?v=4)](https://github.com/fabio-ivona "fabio-ivona (2 commits)")[![Chris8934](https://avatars.githubusercontent.com/u/44963939?v=4)](https://github.com/Chris8934 "Chris8934 (2 commits)")[![veewee](https://avatars.githubusercontent.com/u/1618158?v=4)](https://github.com/veewee "veewee (1 commits)")[![hn-seoai](https://avatars.githubusercontent.com/u/141815664?v=4)](https://github.com/hn-seoai "hn-seoai (1 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (1 commits)")[![AlessandroMinoccheri](https://avatars.githubusercontent.com/u/3356506?v=4)](https://github.com/AlessandroMinoccheri "AlessandroMinoccheri (1 commits)")

---

Tags

architecturephpphpunittesttestingphpunittestarchitecturestucture

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ta-tikoma-phpunit-architecture-test/health.svg)

```
[![Health](https://phpackages.com/badges/ta-tikoma-phpunit-architecture-test/health.svg)](https://phpackages.com/packages/ta-tikoma-phpunit-architecture-test)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k26.2M1.8k](/packages/infection-infection)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[fr3d/swagger-assertions

Test your API requests and responses against your swagger definition

138850.9k5](/packages/fr3d-swagger-assertions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
