Files
XC_VM/tests/Unit/BootstrapPathsTest.php
T
Divarion-D fd35f00c4d fix(views): import migrated classes at top of 5 admin view templates
enigma, episode, episodes, process_monitor and stream_view referenced migrated
classes (UserRepository, BouquetService, StreamRepository, RequestManager,
SettingsManager, ...) by short name with either no `use` or a `use` placed
*below* the first usage. PHP imports outside the top scope are positional, so the
short name resolved to a now-nonexistent global class — a runtime fatal on those
admin pages (php -l passes; not covered by PHPStan/PHPUnit). The migration's
automated `use` insertion missed them due to the interleaved HTML / short-tag
(<? , <?=) structure, and the later php-cs-fixer pass stripped some as 'unused'
because it could not see usage inside short-tag blocks.

- Consolidate every needed `use XcVm\...;` into a single top-of-file PHP block.
- Exclude Public/Views and Modules/*/views from php-cs-fixer (no_unused_imports
  is unreliable on short-tag templates); their import correctness is enforced by
  the new check_procedural_use gate instead.

Verified: php -l (short_open_tag=1) clean; PHPStan no errors; PHPUnit green.
2026-06-25 20:57:37 +03:00

61 lines
2.1 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
/**
* Runtime guard for Фаза 1: after the 7 top-level dirs were renamed to PascalCase
* (core→Core, domain→Domain, ...), no live require/include may still point at a
* lowercase directory name. PHPStan cannot catch these (a constant concatenated
* with a string literal), so they would only fault at runtime on a deployed box.
*
* resources/config/content/signals stay lowercase by design and are NOT checked.
*/
final class BootstrapPathsTest extends TestCase {
/** The 7 renamed directories — their lowercase form must never appear in a require path. */
private const RENAMED = ['core', 'domain', 'infrastructure', 'streaming', 'modules', 'cli', 'public'];
public function testNoLiveRequireUsesALowercaseRenamedDir(): void {
$pattern = '#(?:require|include)(?:_once)?\b[^;]*[\'"](' . implode('|', self::RENAMED) . ')/#';
$violations = [];
foreach ($this->sourceFiles() as $file) {
foreach (file($file) as $no => $line) {
$trimmed = ltrim($line);
if ($trimmed === '' || $trimmed[0] === '*' || str_starts_with($trimmed, '//')
|| str_starts_with($trimmed, '#') || str_starts_with($trimmed, '/*')) {
continue;
}
if (preg_match($pattern, $line, $m)) {
$violations[] = substr($file, strlen(MAIN_HOME)) . ':' . ($no + 1)
. " → '{$m[1]}/' " . trim($line);
}
}
}
$this->assertSame(
[],
$violations,
"Lowercase require/include paths to renamed dirs:\n" . implode("\n", $violations)
);
}
/** @return iterable<string> absolute paths of every .php under src/ except vendor/tmp/backups. */
private function sourceFiles(): iterable {
$it = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator(MAIN_HOME, FilesystemIterator::SKIP_DOTS),
static function (SplFileInfo $current): bool {
$name = $current->getFilename();
if ($current->isDir()) {
return !in_array($name, ['vendor', 'tmp', 'backups'], true);
}
return str_ends_with($name, '.php');
}
)
);
foreach ($it as $file) {
yield $file->getPathname();
}
}
}