Files
tez-utils-arr/tests/FlattenTest.php
T
rhalberstadt 5ed0113590
PHP Composer / build (push) Successful in 37s
Rename namespace to Tezmanian and prepare for Packagist
- Namespace Tez\Utils -> Tezmanian\Utils, package tez/* -> tezmanian/*
- Add keywords, homepage, authors and support metadata
- Drop VCS repositories (resolved via Packagist)
- Remove stale composer.lock, set license holder
2026-10-13 22:22:32 +02:00

66 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tezmanian\Utils\Tests\Arr;
use PHPUnit\Framework\TestCase;
use Tezmanian\Utils\Arr\Flatten;
final class FlattenTest extends TestCase
{
public function testFlattensFullyByDefault(): void
{
$result = Flatten::flatten([1, [2, 3], [4, [5, 6]]]);
self::assertSame([1, 2, 3, 4, 5, 6], $result);
}
public function testDepthOne(): void
{
$result = Flatten::flatten([1, [2, 3], [4, [5, 6]]], depth: 1);
self::assertSame([1, 2, 3, 4, [5, 6]], $result);
}
public function testDepthTwo(): void
{
$result = Flatten::flatten([1, [2, [3, [4]]]], depth: 2);
self::assertSame([1, 2, 3, [4]], $result);
}
public function testAlreadyFlatArrayIsUnchanged(): void
{
$result = Flatten::flatten([1, 2, 3]);
self::assertSame([1, 2, 3], $result);
}
public function testEmptyArrayReturnsEmpty(): void
{
self::assertSame([], Flatten::flatten([]));
}
public function testAssociativeKeysAreDiscarded(): void
{
$result = Flatten::flatten([['a' => 1, 'b' => 2], ['c' => 3]]);
self::assertSame([1, 2, 3], $result);
}
public function testDepthZeroReturnsOriginalValues(): void
{
$result = Flatten::flatten([[1, 2], [3, 4]], depth: 0);
self::assertSame([[1, 2], [3, 4]], $result);
}
public function testMixedNestingDepths(): void
{
$result = Flatten::flatten([1, [2, [3]], 4, [[5]]]);
self::assertSame([1, 2, 3, 4, 5], $result);
}
}