diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 3c5ae10c..37db3ee6 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -42,5 +42,43 @@ jobs: - name: Install Composer Dependencies run: composer install --prefer-dist --no-interaction - - name: Run Tests + - name: 🔍 Run Tests run: vendor/bin/psalm + + arch: + name: Architecture tests + runs-on: ${{ matrix.os }} + continue-on-error: true + strategy: + fail-fast: false + matrix: + php: [8.3] + os: [ubuntu-latest] + steps: + - name: Set up PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom + + - name: Check Out Code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: php-${{ matrix.php }}-${{ runner.os }}-composer- + + - name: Install Composer Dependencies + run: composer install --prefer-dist --no-interaction + + - name: 🔍 Run Tests + run: composer test:arch diff --git a/composer.json b/composer.json index 17a550a7..ab4c7342 100644 --- a/composer.json +++ b/composer.json @@ -62,6 +62,7 @@ "spiral/code-style": "^2.1.2", "spiral/core": "^3.13", "symfony/var-dumper": "^6.0 || ^7.0", + "ta-tikoma/phpunit-architecture-test": "^0.8.4", "vimeo/psalm": "^4.30 || ^5.4" }, "autoload-dev": { @@ -87,6 +88,7 @@ "psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", "test:unit": "phpunit --testsuite=Unit --color=always --testdox", "test:func": "phpunit --testsuite=Functional --color=always --testdox", + "test:arch": "phpunit --testsuite=Arch --color=always --testdox", "test:accept": "phpunit --testsuite=Acceptance --color=always --testdox" }, "extra": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6d0db0da..c2b9b8b0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,6 +14,9 @@ tests/Acceptance/Harness + + tests/Arch + tests/Unit diff --git a/tests/Arch/ArchTest.php b/tests/Arch/ArchTest.php new file mode 100644 index 00000000..df03f1ce --- /dev/null +++ b/tests/Arch/ArchTest.php @@ -0,0 +1,40 @@ +layer(); + + foreach ($layer as $object) { + foreach ($object->uses as $use) { + foreach ($functions as $function) { + $function === $use and throw new \Exception( + \sprintf( + 'Function `%s()` is used in %s.', + $function, + $object->name, + ), + ); + } + } + } + + $this->assertTrue(true); + } +}