Skip to content

Commit 64d30ae

Browse files
committed
Don't allow creating empty list of references
1 parent 1523d77 commit 64d30ae

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/core/etl/src/Flow/ETL/Row/References.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ final class References implements \ArrayAccess, \Countable, \IteratorAggregate
2424

2525
public function __construct(string|Reference ...$references)
2626
{
27+
if ([] === $references) {
28+
throw new InvalidArgumentException('References cannot be empty.');
29+
}
30+
2731
foreach ($references as $ref) {
2832
$ref = EntryReference::init($ref);
2933

src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55
namespace Flow\ETL\Tests\Unit\Row;
66

77
use function Flow\ETL\DSL\{ref, refs};
8+
use Flow\ETL\Exception\InvalidArgumentException;
89
use Flow\ETL\Row\References;
910
use Flow\ETL\Tests\FlowTestCase;
1011

1112
final class ReferencesTest extends FlowTestCase
1213
{
14+
public function test_empty() : void
15+
{
16+
$this->expectException(InvalidArgumentException::class);
17+
$this->expectExceptionMessage('References cannot be empty.');
18+
19+
refs();
20+
}
21+
1322
public function test_lazy_without() : void
1423
{
15-
$refs = refs()->without('id')->add('id')->add('name');
24+
$refs = refs('id')->without('id')->add('id')->add('name');
1625

1726
self::assertEquals(
1827
refs('name')->all(),

0 commit comments

Comments
 (0)