mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-11-01 03:03:23 +01:00
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.
93 lines
3.7 KiB
PHP
93 lines
3.7 KiB
PHP
<?php
|
|
|
|
use XcVm\Core\Config\ConstantsInitializer;
|
|
use XcVm\Core\Events\EventDispatcher;
|
|
use XcVm\Core\Events\Stream\StreamsChangedEvent;
|
|
use XcVm\Domain\Stream\RecordingService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* RecordingService on the TestDb: scheduling validates and stores a recording,
|
|
* deleting removes it, and both tell the recorded stream's node (R2).
|
|
*/
|
|
final class RecordingServiceTest extends TestCase {
|
|
|
|
private const COLUMNS = ['stream_id' => 'int', 'created_id' => 'int', 'category_id' => 'longtext', 'bouquets' => 'longtext', 'title' => 'mediumtext', 'start' => 'int', 'end' => 'int', 'source_id' => 'int', 'status' => 'tinyint'];
|
|
|
|
private TestDb $db;
|
|
private $globalDbBefore;
|
|
/** @var int[][] */
|
|
private array $changed = [];
|
|
|
|
protected function setUp(): void {
|
|
foreach (ConstantsInitializer::statuses() as $rName => $rValue) {
|
|
if (!defined($rName)) {
|
|
define($rName, $rValue);
|
|
}
|
|
}
|
|
$this->db = new TestDb();
|
|
$rColumns = [];
|
|
foreach (self::COLUMNS as $rName => $rType) {
|
|
$rColumns[] = '`' . $rName . '` ' . ($rType === 'varchar' ? 'varchar(255)' : $rType) . ' NULL';
|
|
}
|
|
$this->db->exec('CREATE TABLE recordings (id INTEGER PRIMARY KEY AUTO_INCREMENT, ' . implode(', ', $rColumns) . ');');
|
|
|
|
RecordingService::setDb($this->db);
|
|
$this->globalDbBefore = $GLOBALS['db'] ?? null;
|
|
$GLOBALS['db'] = $this->db;
|
|
EventDispatcher::listen(StreamsChangedEvent::class, function (StreamsChangedEvent $rEvent): void {
|
|
$this->changed[] = $rEvent->streamIds;
|
|
});
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
EventDispatcher::unlisten(StreamsChangedEvent::class);
|
|
$GLOBALS['db'] = $this->globalDbBefore;
|
|
}
|
|
|
|
public function testScheduleRefusesAMissingTitleOrSource(): void {
|
|
$this->assertSame(STATUS_NO_TITLE, RecordingService::schedule(['source_id' => 6])['status']);
|
|
$this->assertSame(STATUS_NO_SOURCE, RecordingService::schedule(['title' => 'News'])['status']);
|
|
$this->assertSame([], RecordingService::getAll());
|
|
$this->assertSame([], $this->changed);
|
|
}
|
|
|
|
public function testScheduleStoresTheRecordingAndTellsItsStream(): void {
|
|
$rResult = RecordingService::schedule(['title' => 'News', 'source_id' => 6, 'stream_id' => 11, 'start' => 100, 'end' => 200, 'bouquets' => ['3', '4'], 'category_id' => ['7']]);
|
|
|
|
$this->assertSame(STATUS_SUCCESS, $rResult['status']);
|
|
$rRows = RecordingService::getAll();
|
|
$this->assertCount(1, $rRows);
|
|
$this->assertSame(['News', '[3,4]', '[7]'], [$rRows[0]['title'], $rRows[0]['bouquets'], $rRows[0]['category_id']]);
|
|
$this->assertSame([[11]], $this->changed);
|
|
}
|
|
|
|
public function testScheduleIgnoresServerOwnedColumnsFromTheForm(): void {
|
|
$this->db->exec("INSERT INTO recordings (id, title) VALUES (1, 'existing');");
|
|
|
|
RecordingService::schedule(['id' => 1, 'created_id' => 500, 'status' => 1, 'title' => 'News', 'source_id' => 6, 'stream_id' => 11]);
|
|
|
|
$rRows = RecordingService::getAll();
|
|
$this->assertSame(['News', 'existing'], array_column($rRows, 'title'), 'a posted id does not overwrite another recording');
|
|
$this->assertNull($rRows[0]['created_id']);
|
|
$this->assertNull($rRows[0]['status']);
|
|
}
|
|
|
|
public function testGetAllListsNewestFirst(): void {
|
|
$this->db->exec("INSERT INTO recordings (id, title) VALUES (1, 'old'), (2, 'new');");
|
|
|
|
$this->assertSame(['new', 'old'], array_column(RecordingService::getAll(), 'title'));
|
|
}
|
|
|
|
public function testDeleteRemovesTheRowAndTellsItsStream(): void {
|
|
$this->db->exec("INSERT INTO recordings (id, stream_id, source_id, title) VALUES (5, 11, 6, 'News');");
|
|
|
|
$this->assertTrue(RecordingService::delete(5));
|
|
$this->assertSame([], RecordingService::getAll());
|
|
$this->assertSame([[11]], $this->changed);
|
|
|
|
RecordingService::delete(99);
|
|
$this->assertSame([[11]], $this->changed, 'an unknown id changes nothing');
|
|
}
|
|
}
|