1
0
Files
fs 6c99c040b2 refactor(support): centralize ID-array normalization in toIntIds()
Consolidates the scattered `array_values(array_unique(array_map('intval',
$x)))` + manual positive-filter pattern behind a single lenient helper
`toIntIds(mixed $value): array` in core/Support/helpers/array.php.

- `RepositoryArrayHelper::sanitizePositiveIds()` now delegates (keeps
  strict array-input contract + existing tests intact).
- Drops two private duplicates: `UserProfileViewService::normalizeIds()`
  and `AddressBookService::normalizeIds()`.
- Replaces 12 inline occurrences across admin action pages with the
  helper, cutting boilerplate by 3-5 lines per site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 19:11:53 +02:00

52 lines
1.2 KiB
PHP

<?php
namespace MintyPHP\Tests\Support\Helpers;
use PHPUnit\Framework\TestCase;
class ToIntIdsTest extends TestCase
{
public function testDeduplicatesAndPreservesOrder(): void
{
$this->assertSame([1, 3, 5], toIntIds([1, 3, 5, 1, 3]));
}
public function testDropsNonPositiveValues(): void
{
$this->assertSame([2, 4], toIntIds([0, -1, 2, -3, 4]));
}
public function testCoercesNumericStrings(): void
{
$this->assertSame([1, 2, 3], toIntIds(['1', '2', '3']));
}
public function testIgnoresNonNumericStrings(): void
{
$this->assertSame([7], toIntIds(['abc', '7', '']));
}
public function testEmptyArrayReturnsEmpty(): void
{
$this->assertSame([], toIntIds([]));
}
public function testNullAndEmptyStringReturnEmpty(): void
{
$this->assertSame([], toIntIds(null));
$this->assertSame([], toIntIds(''));
}
public function testScalarIsWrappedAsSingleElement(): void
{
$this->assertSame([42], toIntIds(42));
$this->assertSame([42], toIntIds('42'));
}
public function testZeroScalarReturnsEmpty(): void
{
$this->assertSame([], toIntIds(0));
$this->assertSame([], toIntIds('0'));
}
}