mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-03 20:02:29 +02:00
Ran `make rector-fix` (deadCode + codeQuality prepared sets) over the PSR-4 class trees (Core/Domain/Cli/Infrastructure). Net -600 lines: dead-code removal and the empty-if/else collapse (the feedback_simplify_empty_else pattern this adoption targeted). 99 files mechanically transformed. The output was reviewed against the full test suite + PHPStan + a targeted scan; this commit is the CORRECTED pass (no broken state in history): - FIX (Rector bug): its boolean inversion dropped the parens around an assignment-in-condition — `if (($rKey = array_search(...)) === false)` became `if ($rKey = array_search(...) !== false)`, assigning the bool to $rKey and unsetting the wrong array offset. Restored parens in 7 sites (BouquetService, ChannelService, CategoryService). PHPStan caught only 1 of the 7; the rest were silent. Added BouquetServiceTest as a regression (proven to fail on the broken form). - FIX (pre-existing, same class): GroupService::removeGroupFromUsers had the identical dropped-parens bug already in the tree — corrected here too. - FIX: ServersCronJob::pingServer returns floor() (float) under an `: int` return type — added an (int) cast. - ACCEPT: LocallyCalledStaticMethodToNonStaticRector converted 25 locally-called private static helpers to instance methods (behaviour-preserving; call sites rewritten). Updated MonitorCommandTest's reflection helper to invoke on a constructor-less instance. Verified: PHPStan level 5 clean (0), suite 691 tests / 0 errors. NOTE: do not re-run `make rector-fix` on this tree without first skipping the inversion rule — the dropped-parens bug is deterministic and would return.
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, 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');
|
|
}
|
|
}
|