Skip to content

Commit

Permalink
Make impossible to merge two schema definitions that are pointing to …
Browse files Browse the repository at this point in the history
…a different entry
  • Loading branch information
norberttech committed Jan 21, 2024
1 parent 4818e7d commit 6664f7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Schema/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function Flow\ETL\DSL\type_xml;
use function Flow\ETL\DSL\type_xml_node;
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Exception\RuntimeException;
use Flow\ETL\PHP\Type\Logical\ListType;
use Flow\ETL\PHP\Type\Logical\MapType;
use Flow\ETL\PHP\Type\Logical\StructureType;
Expand Down Expand Up @@ -239,6 +240,10 @@ public function matches(Entry $entry) : bool

public function merge(self $definition) : self
{
if (!$this->ref->is($definition->ref)) {
throw new RuntimeException(\sprintf('Cannot merge different definitions, %s and %s', $this->ref->name(), $definition->ref->name()));
}

$constraint = new Any($this->constraint, $definition->constraint);

if ($this->constraint instanceof VoidConstraint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function Flow\ETL\DSL\type_map;
use function Flow\ETL\DSL\type_string;
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Exception\RuntimeException;
use Flow\ETL\PHP\Type\Logical\List\ListElement;
use Flow\ETL\PHP\Type\Logical\ListType;
use Flow\ETL\PHP\Type\Logical\StructureType;
Expand Down Expand Up @@ -170,6 +171,14 @@ public function test_merging_anything_with_null() : void
);
}

public function test_merging_different_entries() : void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Cannot merge different definitions, int and string');

Definition::integer('int')->merge(Definition::string('string'));
}

public function test_merging_numeric_types() : void
{
$this->assertEquals(
Expand Down

0 comments on commit 6664f7e

Please sign in to comment.