70 lines
2.8 KiB
PHP
70 lines
2.8 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Tests\Architecture;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use RecursiveDirectoryIterator;
|
|
use RecursiveIteratorIterator;
|
|
|
|
final class Phase8ControllerApiArchitectureTest extends TestCase
|
|
{
|
|
/** @return string[] */
|
|
private function phpFiles(string $relative): array
|
|
{
|
|
$root = dirname(__DIR__, 2).'/'.$relative;
|
|
if (! is_dir($root)) {
|
|
return [];
|
|
}
|
|
$files = [];
|
|
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root)) as $file) {
|
|
if ($file->isFile() && $file->getExtension() === 'php') {
|
|
$files[] = $file->getPathname();
|
|
}
|
|
}
|
|
return $files;
|
|
}
|
|
|
|
public function test_canonical_v2_controllers_do_not_use_raw_db_or_provider_sdks(): void
|
|
{
|
|
foreach ($this->phpFiles('app/Http/Controllers/Api/V2') as $file) {
|
|
$contents = file_get_contents($file);
|
|
$this->assertStringNotContainsString('DB::table', $contents, $file);
|
|
$this->assertStringNotContainsString('Mail::', $contents, $file);
|
|
$this->assertStringNotContainsString('Validator::make', $contents, $file);
|
|
$this->assertStringNotContainsString('max(\'id\')', $contents, $file);
|
|
$this->assertStringNotContainsString('response()->download', $contents, $file);
|
|
}
|
|
}
|
|
|
|
public function test_schoolcore_controllers_do_not_import_islamic_sunday_school_extension_classes(): void
|
|
{
|
|
foreach ($this->phpFiles('app/Http/Controllers/Api/V2') as $file) {
|
|
if (str_contains($file, 'IslamicSundaySchool')) {
|
|
continue;
|
|
}
|
|
$contents = file_get_contents($file);
|
|
$this->assertStringNotContainsString('App\\Domain\\IslamicSundaySchool', $contents, $file);
|
|
}
|
|
}
|
|
|
|
public function test_bulk_send_controller_requires_preview_dto_path(): void
|
|
{
|
|
$file = dirname(__DIR__, 2).'/app/Http/Controllers/Api/V2/Communication/BulkSendController.php';
|
|
$contents = file_get_contents($file);
|
|
$this->assertStringContainsString('BulkSendMessageRequest', $contents);
|
|
$this->assertStringContainsString('sendBulkMessage', $contents);
|
|
$this->assertStringNotContainsString('foreach', $contents, 'Bulk controller must not loop recipients.');
|
|
}
|
|
|
|
public function test_reporting_controllers_delegate_to_reporting_contracts(): void
|
|
{
|
|
$path = dirname(__DIR__, 2).'/app/Http/Controllers/Api/V2/Reporting';
|
|
foreach ($this->phpFiles('app/Http/Controllers/Api/V2/Reporting') as $file) {
|
|
$contents = file_get_contents($file);
|
|
$this->assertStringNotContainsString('select(', $contents, $file);
|
|
$this->assertStringNotContainsString('join(', $contents, $file);
|
|
$this->assertStringContainsString('Contract', $contents, $file);
|
|
}
|
|
}
|
|
}
|