Files
XC_VM/tests/Unit/ServerRepositorySimpleTest.php
T
Divarion_D 9e118da975 test: run the unit suite on MariaDB only, and on the panel's own stack
The suite ran on in-memory SQLite, an engine production never uses: it hid
column lengths, MySQL-only syntax and type coercion (the identity bug fixed in
the previous commit passed CI that way). SQLite is gone:

- TestDb connects only to MariaDB/MySQL (XCVM_TEST_DB_DSN/_USER/_PASS; root over
  the local socket, else 127.0.0.1:3306). Each instance gets a throwaway
  schema, dropped with it, in the installer's sql_mode, with an explicit
  connect timeout (a boot under test can zero default_socket_timeout).
- InstallSchema and the tests take the production DDL as is: the SQLite
  reducers, the keys they re-added, the faked information_schema and the
  sqliteCreateFunction() stand-ins are removed; test DDL is MySQL DDL.
- ReplicaBootTest, DbConnectRefusalTest and LazyDatabaseHandlerTest reach the
  test server instead of SQLite files; RecordingFinalizer no longer swallows
  an information_schema failure "for tests on SQLite".
- `make test-db` starts a throwaway mariadb:11.4 (tmpfs) for a machine without
  a server; the CI PHPUnit job gets the same as a service.

The suite also runs on a panel host with the bundled PHP and its own php.ini:
tests reach the code through MAIN_HOME, not `<repo>/src`; repository checks
and process-isolated tests (ionCube Loader + OPcache CLI segfault on a script
read from stdin) are in the skip-on-panel group; xcvm_test_child_php() starts
a child that fakes \XC_VM without the real extension; Redis-down tests use
RedisManager::useConnector() instead of an eval'd \XC_VM.

Stale opt-in tests fixed on the way: the real-agent provisioning test answers
the agent-started check, the extension integration test sends the typed starts
and reads the binary signature raw, a fake producer starts as PHP_BINARY, and
the certbot test waits for the line its background command writes.
2026-10-04 16:12:23 +03:00

67 lines
2.5 KiB
PHP

<?php
use XcVm\Domain\Server\ServerRepository;
use PHPUnit\Framework\TestCase;
/**
* ServerRepository::getStreamingSimple / getProxySimple — server lists for the
* admin/reseller UI, filtered by permissions.
*
* Regression: these run during admin-API boot on the login page, where the
* $rPermissions global is still null. A strict `array $rPermissions` hint made
* that a fatal TypeError at boot; the parameter must accept null (the methods
* only read it via isset()). Also covers the online filter and reseller name
* masking. Driven against the TestDb via setDb().
*/
final class ServerRepositorySimpleTest extends TestCase {
private TestDb $db;
protected function setUp(): void {
$this->db = new TestDb();
$now = time();
$this->db->exec(
'CREATE TABLE servers (id INTEGER PRIMARY KEY AUTO_INCREMENT, server_type INTEGER, status INTEGER, last_check_ago INTEGER, is_main INTEGER, `order` INTEGER, server_name TEXT);'
);
$this->db->query(
'INSERT INTO servers (id, server_type, status, last_check_ago, is_main, `order`, server_name) VALUES
(1, 0, 1, ?, 0, 0, "Stream-1"),
(2, 0, 2, ?, 0, 0, "Stream-2"),
(3, 1, 1, ?, 0, 0, "Proxy-1");',
$now,
$now - 100000,
$now
);
ServerRepository::setDb($this->db);
}
protected function tearDown(): void {
// The injected connection would outlive this test and stand in for the next one's.
(new ReflectionProperty(ServerRepository::class, 'db'))->setValue(null, null);
}
public function testGetStreamingSimpleAcceptsNullPermissions(): void {
// Regression: null perms (login-page boot) must not throw.
$servers = ServerRepository::getStreamingSimple(null);
$this->assertSame([1], array_keys($servers), 'only the online streaming server');
$this->assertSame('Stream-1', $servers[1]['server_name'], 'name not masked without reseller perms');
}
public function testGetStreamingSimpleAllTypeReturnsOfflineToo(): void {
$servers = ServerRepository::getStreamingSimple(null, 'all');
$this->assertSame([1, 2], array_keys($servers), 'both streaming servers, proxy excluded');
}
public function testGetStreamingSimpleMasksNamesForResellers(): void {
$servers = ServerRepository::getStreamingSimple(['is_reseller' => 1], 'all');
$this->assertSame('Server #1', $servers[1]['server_name']);
$this->assertSame('Server #2', $servers[2]['server_name']);
}
public function testGetProxySimpleAcceptsNullPermissions(): void {
$proxies = ServerRepository::getProxySimple(null);
$this->assertSame([3], array_keys($proxies), 'only proxy-type servers');
}
}