Files
XC_VM/tests/Unit/StartupCommandRuntimeFilesTest.php
T
Divarion_D 489555f039 refactor: apply the Rector stage-2 pass and keep its helpers reachable from tests
Mechanical output of `make rector-fix` over the class-based trees, reviewed
change by change. Most of it is empty()/=== [] normalisation, a chained === turned
into in_array(..., true) in FanoutConfig, and multi-line condition reformatting.

Three changes were checked more closely because they looked behaviour-affecting:

- Translator::isRtl() loses its (string) cast on $lang. Safe: $currentLang is a
  non-nullable `private static string`, so the ??= above always leaves a string.
- TableController loses htmlValue() and jsArgument(). They are escaping helpers,
  so the removal was verified rather than trusted: neither has a single reference
  anywhere under src/, views included. Genuinely dead.
- StartupCommand and StreamsCronJob have three private helpers turned from static
  into instance methods (LocallyCalledStaticMethodToNonStatic).

That last one broke 7 tests, which reached the helpers through Reflection and
invoked them statically. Fixed in the tests rather than by reverting the rule —
reverting would only lose the argument again on the next `make rector-fix`. The
Reflection helpers now bind an instance only when the method needs one, so they
survive the flip in either direction.

Also re-ran the two KNOWN BUG greps from build/rector.php (the rules that drop
parens around an assignment-in-condition and invert the guard): both clean.

Verified: 857 tests, make gates, make cs, CRAP gate.
2026-09-22 18:19:45 +03:00

60 lines
2.1 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
use XcVm\Cli\Commands\StartupCommand;
/**
* Coverage for the boot self-healing helpers extracted from StartupCommand:
* restoring the executable bit on core scripts and regenerating missing
* php-fpm pool configs from the template.
*/
final class StartupCommandRuntimeFilesTest extends TestCase {
private string $dir;
/**
* Call a private helper. Whether it is static is an implementation detail
* (Rector's LocallyCalledStaticMethodToNonStatic flips it), so bind an
* instance only when the method actually needs one.
*/
private function call(string $rMethod, ...$rArgs) {
$rM = new ReflectionMethod(StartupCommand::class, $rMethod);
$rM->setAccessible(true);
return $rM->invoke($rM->isStatic() ? null : new StartupCommand(), ...$rArgs);
}
protected function setUp(): void {
$this->dir = sys_get_temp_dir() . '/xcvm_startup_' . uniqid() . '/';
mkdir($this->dir . 'bin/php/etc', 0777, true);
}
protected function tearDown(): void {
exec('rm -rf ' . escapeshellarg($this->dir));
}
public function testEnsureExecutableScriptsSetsBitAndSkipsMissing(): void {
file_put_contents($this->dir . 'service', "#!/bin/sh\n");
chmod($this->dir . 'service', 0644);
$this->call('ensureExecutableScripts', ['service', 'does-not-exist'], $this->dir);
$this->assertTrue(is_executable($this->dir . 'service'));
}
public function testEnsurePhpFpmPoolConfigsGeneratesOnlyMissing(): void {
file_put_contents($this->dir . 'bin/php/etc/template', 'id=#ID# path=#PATH#');
file_put_contents($this->dir . 'bin/php/etc/1.conf', 'KEEP'); // existing → untouched
$this->call('ensurePhpFpmPoolConfigs', $this->dir);
$this->assertSame('KEEP', file_get_contents($this->dir . 'bin/php/etc/1.conf'));
$this->assertSame('id=2 path=' . $this->dir, file_get_contents($this->dir . 'bin/php/etc/2.conf'));
$this->assertFileExists($this->dir . 'bin/php/etc/4.conf');
}
public function testEnsurePhpFpmPoolConfigsWithoutTemplateIsNoop(): void {
$this->call('ensurePhpFpmPoolConfigs', $this->dir);
$this->assertFileDoesNotExist($this->dir . 'bin/php/etc/1.conf');
}
}