ldc-arcadia-api/tests/Architecture/CodingStandardsTest.php
Jérémy Munsch 41dbb04963
test(Architecture): ensure all Unit and Integration tests declare covers()
Added a test to verify that every Unit and Integration test file contains a covers() declaration.
2026-08-13 12:02:43 +02:00

101 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Architecture;
describe('Coding Standards & Project Rules', function (): void {
arch()->preset()->php();
// Le helper assert natif est interdit en faveur de Webmozart\Assert
arch()->preset()->security();
arch('assert is not used in src (use Webmozart\Assert instead)')
->expect('assert')
->not->toBeUsed();
arch('config() helper is not used in src (use Config facade instead)')
->expect('config')
->not->toBeUsed();
arch('env() helper is not used in src (use Config facade instead)')
->expect('env')
->not->toBeUsed();
arch('debug functions are not used in src')
->expect(['dd', 'dump', 'var_dump', 'die', 'print_r', 'ray'])
->not->toBeUsed();
arch('shell execution functions are not used in src')
->expect(['exec', 'shell_exec', 'system', 'passthru', 'proc_open'])
->not->toBeUsed();
arch('eval function is not used in src')
->expect('eval')
->not->toBeUsed();
arch('insecure hashing functions are not used in src')
->expect(['md5', 'sha1'])
->not->toBeUsed();
arch('sleep functions are not used in src')
->expect(['sleep', 'usleep'])
->not->toBeUsed();
arch('all Domain source files use strict types')
->expect('Domain')
->toUseStrictTypes();
arch('all Application source files use strict types')
->expect('Application')
->toUseStrictTypes();
arch('all Presentation source files use strict types')
->expect('Presentation')
->toUseStrictTypes();
arch('all Infra source files use strict types')
->expect('Infra')
->toUseStrictTypes();
arch('all Shared source files use strict types')
->expect('Shared')
->toUseStrictTypes();
arch('all test files belong to Tests namespace and use strict types')
->expect('Tests')
->toUseStrictTypes();
it('ensures every test file in tests directory has a namespace', function (): void {
/** @var array<int, string> $testFiles */
$testFiles = glob(base_path('tests/{*,*/*,*/*/*,*/*/*/*}.php'), GLOB_BRACE);
foreach ($testFiles as $file) {
if (preg_match('/Test\.php$/', basename($file)) !== 1) {
continue;
}
$content = (string) file_get_contents($file);
expect($content)->toMatch(
'/^\s*namespace\s+Tests/m',
"File [{$file}] is missing a namespace Tests declaration."
);
}
});
it('ensures every Unit and Integration test file contains a covers() call', function (): void {
/** @var array<int, string> $testFiles */
$testFiles = glob(base_path('{tests/Unit,tests/Integration}/{*,*/*,*/*/*,*/*/*/*}.php'), GLOB_BRACE);
foreach ($testFiles as $file) {
if (preg_match('/Test\.php$/', basename($file)) !== 1) {
continue;
}
$content = (string) file_get_contents($file);
expect($content)->toMatch(
'/^\s*covers\s*\(/m',
"Test file [{$file}] is missing a covers(...) declaration."
);
}
});
});