Skip to content

Commit

Permalink
added Structure::extend() [Closes #66]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 4, 2024
1 parent 9ff5667 commit e56fa05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Schema/Elements/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public function skipDefaults(bool $state = true): self
}


public function extend(array $items): self
{
return new self($items + $this->items);
}


/********************* processing ****************d*g**/


Expand Down
10 changes: 10 additions & 0 deletions tests/Schema/Expect.structure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,13 @@ test('processing without default values skipped on structure', function () {
$processor->process($schema, []),
);
});


test('extend', function () {
$schema = Expect::structure(['a' => Expect::string(), 'b' => Expect::string()]);

Assert::equal(
Expect::structure(['a' => Expect::int(), 'b' => Expect::string(), 'c' => Expect::int()]),
$schema->extend(['a' => Expect::int(), 'c' => Expect::int()]),
);
});

0 comments on commit e56fa05

Please sign in to comment.