Skip to content

Commit

Permalink
Add architecture tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Oct 28, 2024
1 parent 14f69e9 commit ed75242
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
40 changes: 39 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<testsuite name="Acceptance">
<directory suffix="Test.php">tests/Acceptance/Harness</directory>
</testsuite>
<testsuite name="Arch">
<directory suffix="Test.php">tests/Arch</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="TestCase.php">tests/Unit</directory>
</testsuite>
Expand Down
40 changes: 40 additions & 0 deletions tests/Arch/ArchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Arch;

use PHPUnit\Architecture\ArchitectureAsserts;
use PHPUnit\Framework\TestCase;

final class ArchTest extends TestCase
{
protected array $excludedPaths = [
'vendor',
'tests',
];

use ArchitectureAsserts;

public function testDontForgetDebugFunctions(): void
{
$functions = ['dump', 'trap', 'tr', 'td', 'var_dump'];
$layer = $this->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);
}
}

0 comments on commit ed75242

Please sign in to comment.