mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-09-26 04:02:51 +02:00
First step of untangling MonitorCommand::execute()'s obfuscated goto control flow. The FPS baseline computation flattened a "30/1" -> 30.0 rational parse across five labels (label768/780/1047/1052/1057). Pull the pure parse into parseFrameRate() with unit tests; the label768 entry and the label1847 exit are kept so control flow is unchanged -- four labels and their gotos are gone. Guards a zero denominator (PHP 8 would otherwise throw on "x/0") -- an input ffprobe does not produce, so behaviour is unchanged in practice. PHPStan cannot see the self::parseFrameRate call through the surrounding goto maze and reports the method unused; baselined until the label768 region is destructured, then the entry drops out. Verified: phpstan level 5 green, phpunit 408/408, make gates green.
39 lines
1.4 KiB
PHP
39 lines
1.4 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Cli\Commands\MonitorCommand;
|
|
|
|
/**
|
|
* Unit tests for pure helpers extracted from MonitorCommand's obfuscated
|
|
* goto-based execute(). Each helper replaces a self-contained goto cluster; the
|
|
* tests lock its behaviour so the control-flow untangling cannot silently drift.
|
|
*/
|
|
final class MonitorCommandTest extends TestCase {
|
|
|
|
/** Invoke a private static MonitorCommand method via reflection. */
|
|
private function call(string $method, ...$args) {
|
|
$m = new ReflectionMethod(MonitorCommand::class, $method);
|
|
$m->setAccessible(true);
|
|
return $m->invoke(null, ...$args);
|
|
}
|
|
|
|
// ── parseFrameRate (label768/780/1047/1052/1057) ───────────
|
|
|
|
public function testPlainInteger(): void {
|
|
$this->assertSame(30.0, $this->call('parseFrameRate', '30'));
|
|
$this->assertSame(25.0, $this->call('parseFrameRate', 25));
|
|
}
|
|
|
|
public function testRationalFrameRate(): void {
|
|
$this->assertSame(25.0, $this->call('parseFrameRate', '25/1'));
|
|
$this->assertEqualsWithDelta(29.97, $this->call('parseFrameRate', '30000/1001'), 0.001);
|
|
}
|
|
|
|
public function testZeroAndMalformedAreZero(): void {
|
|
$this->assertSame(0.0, $this->call('parseFrameRate', ''));
|
|
$this->assertSame(0.0, $this->call('parseFrameRate', '0'));
|
|
$this->assertSame(0.0, $this->call('parseFrameRate', '0/0'), 'division-by-zero guarded');
|
|
$this->assertSame(0.0, $this->call('parseFrameRate', '30/0'), 'zero denominator guarded');
|
|
}
|
|
}
|