what it is). */ private const FORBIDDEN = [ '/new\s+\\\\?PDO\b/' => 'own database connection', '/->getPdo\(/' => 'raw database handle', '/\b(fsockopen|pfsockopen|stream_socket_client|socket_create)\s*\(/' => 'socket', '/\bcurl_[a-z_]+\s*\(/' => 'curl', '/(?:$])(? 'mail()', '/(?:$])(? 'file by path', '/(?:])(exec|shell_exec|passthru|system|popen|proc_open)\s*\(/' => 'program', '/(?:$])env\s*\(/' => 'environment outside config/', '/\bgetenv\s*\(/' => 'environment outside config/', ]; /** Files allowed to use a forbidden call, with the reason. */ private const ALLOWED = [ 'Console/Commands/BackupDatabase.php' => 'backup of the real database; console only, never reachable in a tester run (no scheduler there)', 'Console/Commands/ProcessCheck.php' => 'writes MODULMATRIX.md (developer command)', 'Console/Commands/ProcessSandboxRun.php' => 'writes the report into the run directory', 'Console/Commands/ProcessSandboxTemplate.php' => 'builds the template file', 'Filament/Resources/Guests/Pages/ListGuests.php' => 'CSV download to php://output', 'Process/Tester/EffectLedger.php' => 'appends to the run ledger', 'Process/Tester/ProcessSandbox.php' => 'slot locks and the check of proc_open', 'Process/Tester/SandboxBootstrapper.php' => 'reads FEWO_SANDBOX_RUN and copies the template before the application starts', 'Process/Tester/SandboxSnapshot.php' => 'none expected', ]; public function test_no_native_way_around_the_framework_in_the_application(): void { $violations = []; foreach (Finder::create()->files()->in(app_path())->name('*.php') as $file) { $relative = str_replace('\\', '/', $file->getRelativePathname()); if (array_key_exists($relative, self::ALLOWED)) { continue; } $code = (string) preg_replace('~//[^\n]*|/\*.*?\*/~s', '', $file->getContents()); foreach (self::FORBIDDEN as $pattern => $what) { if (preg_match($pattern, $code, $match) === 1) { $violations[] = "{$relative}: {$what} ({$match[0]})"; } } } $this->assertSame([], $violations, 'Native calls bypass the process tester\'s isolation โ€“ use Laravel facades (DB, Http, Mail, Storage, Process).'); } }