38 lines
995 B
PHP
38 lines
995 B
PHP
![]() |
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace Loom\Utility\Collection\Tests;
|
||
|
|
||
|
use Loom\Utility\Collection\Collection;
|
||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
|
||
|
class CollectionTest extends TestCase
|
||
|
{
|
||
|
#[DataProvider('addDataProvider')]
|
||
|
public function testAdd(array $startingItems, mixed $itemToAdd, array $expectedResult): void
|
||
|
{
|
||
|
$collection = new Collection($startingItems);
|
||
|
$collection->add($itemToAdd);
|
||
|
|
||
|
$this->assertEquals($expectedResult, $collection->toArray());
|
||
|
}
|
||
|
|
||
|
public static function addDataProvider(): array
|
||
|
{
|
||
|
return [
|
||
|
[
|
||
|
'startingItems' => ['apple', 'banana', 'cherry'],
|
||
|
'itemToAdd' => 'grape',
|
||
|
'expectedResult' => ['apple', 'banana', 'cherry', 'grape'],
|
||
|
],
|
||
|
[
|
||
|
'startingItems' => [],
|
||
|
'itemToAdd' => 1,
|
||
|
'expectedResult' => [1],
|
||
|
],
|
||
|
|
||
|
];
|
||
|
}
|
||
|
}
|