mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-31 11:03:22 +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.7 KiB
PHP
78 lines
2.7 KiB
PHP
<?php
|
|
|
|
use XcVm\Domain\Bouquet\BouquetService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* BouquetService::removeItems — regression for the assignment-in-condition bug.
|
|
*
|
|
* removeItems() finds each id in the bouquet's item list and unsets it by key:
|
|
* if (($rKey = array_search($rID, $rChannels)) !== false) { unset($rChannels[$rKey]); }
|
|
*
|
|
* A Rector inversion once dropped the parens (`$rKey = array_search(...) !== false`),
|
|
* which assigns the boolean to $rKey and unsets offset 1 — removing the wrong
|
|
* element. These tests remove elements NOT at index 1 so that broken variant
|
|
* fails, and confirm the correct element is removed. Driven against TestDb.
|
|
*/
|
|
final class BouquetServiceTest extends TestCase {
|
|
|
|
private TestDb $db;
|
|
|
|
protected function setUp(): void {
|
|
$this->db = new TestDb();
|
|
$this->db->exec(
|
|
'CREATE TABLE bouquets (id INTEGER PRIMARY KEY AUTO_INCREMENT, bouquet_channels TEXT, bouquet_movies TEXT, bouquet_radios TEXT, bouquet_series TEXT);'
|
|
);
|
|
$this->db->query(
|
|
'INSERT INTO bouquets (id, bouquet_channels, bouquet_movies, bouquet_radios, bouquet_series) VALUES (1, ?, ?, "[]", "[]");',
|
|
'[10,20,30]',
|
|
'[5,6]'
|
|
);
|
|
BouquetService::setDb($this->db);
|
|
}
|
|
|
|
private function channels(): array {
|
|
$this->db->query('SELECT `bouquet_channels` FROM `bouquets` WHERE `id` = 1;');
|
|
return json_decode($this->db->get_col(), true);
|
|
}
|
|
|
|
private function movies(): array {
|
|
$this->db->query('SELECT `bouquet_movies` FROM `bouquets` WHERE `id` = 1;');
|
|
return json_decode($this->db->get_col(), true);
|
|
}
|
|
|
|
public function testRemovesTheLastElementNotIndexOne(): void {
|
|
// id 30 is at index 2 — the broken variant would unset index 1 (=> 20).
|
|
BouquetService::removeItems('stream', 1, [30]);
|
|
$this->assertSame([10, 20], $this->channels());
|
|
}
|
|
|
|
public function testRemovesTheFirstElement(): void {
|
|
// id 10 is at index 0 — the broken variant would unset index 1 (=> 20).
|
|
BouquetService::removeItems('stream', 1, [10]);
|
|
$this->assertSame([20, 30], $this->channels());
|
|
}
|
|
|
|
public function testRemovesMultipleIds(): void {
|
|
BouquetService::removeItems('stream', 1, [10, 30]);
|
|
$this->assertSame([20], $this->channels());
|
|
}
|
|
|
|
public function testRemovingAbsentIdLeavesListUnchanged(): void {
|
|
BouquetService::removeItems('stream', 1, [999]);
|
|
$this->assertSame([10, 20, 30], $this->channels());
|
|
}
|
|
|
|
public function testAcceptsAScalarId(): void {
|
|
// array|int|string param: a single scalar is wrapped, not fatal.
|
|
BouquetService::removeItems('stream', 1, 20);
|
|
$this->assertSame([10, 30], $this->channels());
|
|
}
|
|
|
|
public function testTypeSelectsTheMoviesColumn(): void {
|
|
BouquetService::removeItems('movie', 1, [5]);
|
|
$this->assertSame([6], $this->movies());
|
|
$this->assertSame([10, 20, 30], $this->channels(), 'channels untouched');
|
|
}
|
|
}
|