Files
XC_VM/tests/Unit/RedisInstanceGuardTest.php
T
Divarion_D 653fd00c18 refactor(reseller): split ResellerApiDispatcher into Reseller\Ajax controllers
The reseller panel's api?action=… handlers lived in one 1300-line
Infrastructure class behind ResellerApiController. They are HTTP handlers,
so they now sit under Public/Controllers/Reseller/Ajax, one controller per
group (stats, lines, devices, users, streams, activation codes), and are
registered with $router->api() as the admin panel's are. Handler bodies
moved verbatim; BaseResellerAjaxController::begin() keeps the guards the
single endpoint applied to every action. An unknown action now answers
{"result":false} from ResellerApiController.

Tests reach the actions through routes/reseller.php and dispatchApi()
(tests/Support/ResellerAjax). The old file is dropped from the LB strip
list and recorded in deleted_files.txt.
2026-10-16 19:28:11 +03:00

33 lines
1.2 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
/**
* RedisManager::instance() returns null when Redis is unreachable (down, or in
* the connect backoff), so a bare instance()->method() call fatals then. These
* two sites used to do exactly that — a 500 on the reseller "kill connection"
* action and an uncaught TypeError (past the RedisException catch) in the
* signals daemon. They must take instance() into a variable and guard it, like
* the rest of the codebase (StoredConnections, ConnectionIngest, …).
*/
final class RedisInstanceGuardTest extends TestCase {
/** @return array<string, array{0: string}> */
public static function files(): array {
return [
'reseller line ajax' => ['Public/Controllers/Reseller/Ajax/LineAjaxController.php'],
'signals daemon' => ['Cli/Commands/SignalsCommand.php'],
];
}
/** @dataProvider files */
public function testNoUnguardedInstanceMethodCall(string $rRel): void {
$rSrc = (string) file_get_contents(MAIN_HOME . $rRel);
$this->assertDoesNotMatchRegularExpression(
'/RedisManager::instance\(\)\s*->/',
$rSrc,
$rRel . ' calls a method straight on RedisManager::instance() (null when Redis is down) — capture it in a variable and guard for null first'
);
}
}