mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-11-07 11:03:41 +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.
78 lines
2.9 KiB
PHP
78 lines
2.9 KiB
PHP
<?php
|
|
|
|
use XcVm\Domain\Stream\StreamConfigRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Sample of the TestDb harness: exercises a real repository against an
|
|
* in-memory database injected via setDb().
|
|
*
|
|
* @covers StreamConfigRepository
|
|
*/
|
|
final class StreamConfigRepositoryTest extends TestCase {
|
|
|
|
private TestDb $db;
|
|
|
|
protected function setUp(): void {
|
|
$this->db = new TestDb();
|
|
$this->db->exec(
|
|
'CREATE TABLE profiles (profile_id INTEGER PRIMARY KEY AUTO_INCREMENT, profile_name TEXT);
|
|
CREATE TABLE streams (id INTEGER PRIMARY KEY AUTO_INCREMENT, transcode_profile_id INTEGER DEFAULT 0);
|
|
CREATE TABLE watch_folders (id INTEGER PRIMARY KEY AUTO_INCREMENT, transcode_profile_id INTEGER DEFAULT 0);
|
|
CREATE TABLE streams_arguments (id INTEGER PRIMARY KEY AUTO_INCREMENT, argument_key TEXT, argument_cmd TEXT);
|
|
|
|
INSERT INTO profiles (profile_id, profile_name) VALUES (1, "CPU"), (2, "GPU");
|
|
INSERT INTO streams (id, transcode_profile_id) VALUES (10, 2), (11, 1);
|
|
INSERT INTO watch_folders (id, transcode_profile_id) VALUES (5, 2);
|
|
INSERT INTO streams_arguments (id, argument_key, argument_cmd) VALUES
|
|
(1, "cookie", "-headers ?"), (2, "useragent", "-user_agent ?");'
|
|
);
|
|
|
|
StreamConfigRepository::setDb($this->db);
|
|
}
|
|
|
|
public function testGetTranscodeProfilesReturnsAll() {
|
|
$profiles = StreamConfigRepository::getTranscodeProfiles();
|
|
$this->assertCount(2, $profiles);
|
|
$this->assertSame('CPU', $profiles[0]['profile_name']);
|
|
}
|
|
|
|
public function testGetTranscodeProfileByIdReturnsRow() {
|
|
$profile = StreamConfigRepository::getTranscodeProfile(2);
|
|
$this->assertIsArray($profile);
|
|
$this->assertSame('GPU', $profile['profile_name']);
|
|
}
|
|
|
|
public function testGetTranscodeProfileReturnsNullWhenMissing() {
|
|
$this->assertNull(StreamConfigRepository::getTranscodeProfile(999));
|
|
}
|
|
|
|
public function testGetStreamArgumentsKeyedByArgumentKey() {
|
|
$args = StreamConfigRepository::getStreamArguments();
|
|
$this->assertArrayHasKey('cookie', $args);
|
|
$this->assertArrayHasKey('useragent', $args);
|
|
$this->assertSame('-user_agent ?', $args['useragent']['argument_cmd']);
|
|
}
|
|
|
|
public function testDeleteProfileRemovesRowAndDetachesReferences() {
|
|
$this->assertTrue(StreamConfigRepository::deleteProfile(2));
|
|
|
|
// Profile gone.
|
|
$this->assertNull(StreamConfigRepository::getTranscodeProfile(2));
|
|
|
|
// References reset to 0; the unrelated stream keeps its profile.
|
|
$this->db->query('SELECT transcode_profile_id FROM streams WHERE id = ?;', 10);
|
|
$this->assertSame(0, (int) $this->db->get_col());
|
|
|
|
$this->db->query('SELECT transcode_profile_id FROM streams WHERE id = ?;', 11);
|
|
$this->assertSame(1, (int) $this->db->get_col());
|
|
|
|
$this->db->query('SELECT transcode_profile_id FROM watch_folders WHERE id = ?;', 5);
|
|
$this->assertSame(0, (int) $this->db->get_col());
|
|
}
|
|
|
|
public function testDeleteProfileReturnsFalseWhenMissing() {
|
|
$this->assertFalse(StreamConfigRepository::deleteProfile(999));
|
|
}
|
|
}
|