mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-03 12:02:29 +02:00
Reviewed Rector batch (3 files) + a manual decomposition of massEdit on top.
Rector batch (reviewed against suite + PHPStan):
- FIX (recurring Rector bug): the boolean inversion again dropped the parens on
an assignment-in-condition in massEdit (array_search category DEL) — restored.
- massEdit: many correct empty-if/else -> guard inversions (verified).
- strlen(x) > 0 -> x !== '' in saveStreamOptions, TMDbService::buildUrl and
ResellerTableRenderer (behaviour-preserving).
massEdit decomposition (166 -> 96 lines, nesting ~10 -> 7), test-first:
- computeCategoryChange() — ADD union / DEL remove / SET replace (pure)
- planBouquetChanges() — SET/ADD/DEL bouquet attach/detach plan (pure)
- planServerTreeForStream()— per-stream streams_servers reconcile (update in
place / batch-insert buffer / delete marking)
- raiseTimeLimits() — the set_time_limit + ini_set block, shared with
massDelete (de-duplicated)
Tests: RadioServiceTest gains computeCategoryChange (5) + planBouquetChanges (3);
new RadioServiceMassEditTest characterizes massEdit end to end (invalid input,
and the server-tree ADD path) — it has no verifyPostTable/exit and
StreamProcess::updateStreams is a no-op with caching off, so the whole method
runs against the SQLite harness. That test guarded the server_tree extraction.
PHPStan level 5 clean; suite 721 tests / 0 errors.
74 lines
2.8 KiB
PHP
74 lines
2.8 KiB
PHP
<?php
|
|
|
|
use XcVm\Core\Config\SettingsManager;
|
|
use XcVm\Domain\Bouquet\BouquetService;
|
|
use XcVm\Domain\Stream\RadioService;
|
|
use XcVm\Infrastructure\Database\DatabaseFactory;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
if (!defined('STATUS_SUCCESS')) {
|
|
define('STATUS_SUCCESS', 1);
|
|
}
|
|
if (!defined('STATUS_INVALID_INPUT')) {
|
|
define('STATUS_INVALID_INPUT', 34);
|
|
}
|
|
|
|
/**
|
|
* RadioService::massEdit() — method-level characterization, to guard the
|
|
* server_tree extraction / flattening that follows.
|
|
*
|
|
* massEdit has no verifyPostTable/exit(), and StreamProcess::updateStreams is a
|
|
* no-op while enable_cache is off, so the whole method runs against the SQLite
|
|
* TestDb. These lock the outer flow (invalid input) and the server-tree ADD path
|
|
* (a new streams_servers row via the batch insert).
|
|
*/
|
|
final class RadioServiceMassEditTest extends TestCase {
|
|
|
|
private TestDb $db;
|
|
|
|
protected function setUp(): void {
|
|
$this->db = new TestDb();
|
|
$this->db->exec(
|
|
'CREATE TABLE streams (id INTEGER PRIMARY KEY, category_id TEXT);
|
|
CREATE TABLE streams_servers (server_stream_id INTEGER PRIMARY KEY AUTOINCREMENT, stream_id INTEGER, server_id INTEGER, parent_id INTEGER, on_demand INTEGER);
|
|
CREATE TABLE bouquets (id INTEGER PRIMARY KEY AUTOINCREMENT, bouquet_name TEXT, bouquet_channels TEXT, bouquet_movies TEXT, bouquet_series TEXT, bouquet_radios TEXT, bouquet_order INTEGER DEFAULT 0);'
|
|
);
|
|
DatabaseFactory::set($this->db);
|
|
// BouquetService may carry an injected db from another test; override it.
|
|
BouquetService::setDb($this->db);
|
|
SettingsManager::set([]); // enable_cache off → StreamProcess::updateStreams is a no-op
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
SettingsManager::set([]);
|
|
}
|
|
|
|
public function testInvalidInputWhenStreamsNotAnArray(): void {
|
|
$rResult = RadioService::massEdit(['streams' => 'not-json']);
|
|
$this->assertSame(STATUS_INVALID_INPUT, $rResult['status']);
|
|
}
|
|
|
|
public function testServerTreeAddInsertsNewAttachment(): void {
|
|
$rResult = RadioService::massEdit([
|
|
'streams' => json_encode([100]),
|
|
'c_server_tree' => '1',
|
|
'server_type' => 'ADD',
|
|
'server_tree_data' => json_encode([
|
|
['id' => '0', 'parent' => '#'], // root — skipped
|
|
['id' => '2', 'parent' => 'source'], // attach, parent NULL
|
|
]),
|
|
'on_demand' => [],
|
|
]);
|
|
|
|
$this->assertSame(STATUS_SUCCESS, $rResult['status']);
|
|
|
|
$this->db->query('SELECT `stream_id`, `server_id`, `parent_id`, `on_demand` FROM `streams_servers`;');
|
|
$rRows = $this->db->get_rows();
|
|
$this->assertCount(1, $rRows, 'one attachment inserted (root skipped)');
|
|
$this->assertSame(100, (int) $rRows[0]['stream_id']);
|
|
$this->assertSame(2, (int) $rRows[0]['server_id']);
|
|
$this->assertNull($rRows[0]['parent_id'], "'source' parent stored as NULL");
|
|
$this->assertSame(0, (int) $rRows[0]['on_demand']);
|
|
}
|
|
}
|