Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Domain/Value/Field/FieldCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ final class FieldCollection implements \Countable, \IteratorAggregate
private array $items = [];

/**
* @param list<Field> $items
* @param list<Field|string> $items
*/
public function __construct(
array $items = [],
) {
foreach ($items as $item) {
if (\is_string($item)) {
$item = new Field($item);
}

$this->add($item);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Domain/Value/IdCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ final class IdCollection implements \Countable, \IteratorAggregate
private array $items = [];

/**
* @param list<Id> $items
* @param list<Id|int> $items
*/
public function __construct(
array $items = [],
) {
foreach ($items as $item) {
if (\is_int($item)) {
$item = new Id($item);
}

$this->add($item);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Domain/Value/Resolver/RelationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ final class RelationCollection implements \Countable, \IteratorAggregate
private array $items = [];

/**
* @param list<Relation> $items
* @param list<Relation|string> $items
*/
public function __construct(
array $items = [],
) {
foreach ($items as $item) {
if (\is_string($item)) {
$item = new Relation($item);
}

$this->add($item);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Domain/Value/Tag/TagCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ final class TagCollection implements \Countable, \IteratorAggregate
private array $items = [];

/**
* @param list<Tag> $items
* @param list<string|Tag> $items
*/
public function __construct(
array $items = [],
) {
foreach ($items as $item) {
if (\is_string($item)) {
$item = new Tag($item);
}

$this->add($item);
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Domain/Value/Field/FieldCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ final class FieldCollectionTest extends TestCase
{
use FakerTrait;

/**
* @test
*/
public function constructWithString(): void
{
$faker = self::faker();
$collection = new FieldCollection([$faker->word(), $faker->word()]);

self::assertCount(2, $collection);
self::assertContainsOnlyInstancesOf(Field::class, $collection);
}

/**
* @test
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Domain/Value/IdCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ final class IdCollectionTest extends TestCase
{
use FakerTrait;

/**
* @test
*/
public function constructWithString(): void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function constructWithString(): void
public function constructWithInt(): void

{
$faker = self::faker();
$collection = new IdCollection([$faker->numberBetween(1), $faker->numberBetween(1)]);

self::assertCount(2, $collection);
self::assertContainsOnlyInstancesOf(Id::class, $collection);
}

/**
* @test
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Domain/Value/Resolver/RelationCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ final class RelationCollectionTest extends TestCase
{
use FakerTrait;

/**
* @test
*/
public function constructWithString(): void
{
$faker = self::faker();
$collection = new RelationCollection([$faker->relation(), $faker->relation()]);

self::assertCount(2, $collection);
self::assertContainsOnlyInstancesOf(Relation::class, $collection);
}

/**
* @test
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Domain/Value/Tag/TagCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ final class TagCollectionTest extends TestCase
{
use FakerTrait;

/**
* @test
*/
public function constructWithString(): void
{
$faker = self::faker();
$collection = new TagCollection([$faker->word(), $faker->word()]);

self::assertCount(2, $collection);
self::assertContainsOnlyInstancesOf(Tag::class, $collection);
}

/**
* @test
*/
Expand Down