Skip to content

Commit 8fe865d

Browse files
committed
duplicate property validation
1 parent 4ffc17a commit 8fe865d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Space.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function __construct(Mapper $mapper, $id, $name)
2828
public function addProperty($name, $type)
2929
{
3030
$format = $this->getFormat();
31+
foreach($format as $field) {
32+
if($field['name'] == $name) {
33+
throw new Exception("Property $name exists");
34+
}
35+
}
3136
$format[] = compact('name', 'type');
3237
$this->format = $format;
3338
$this->mapper->getClient()->evaluate("box.space[$this->id]:format(...)", [$format]);

tests/SchemaTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
class SchemaTest extends TestCase
77
{
8+
public function testDuplicateProperty()
9+
{
10+
$mapper = $this->createMapper();
11+
$this->clean($mapper);
12+
13+
$space = $mapper->getSchema()->createSpace('tester');
14+
$space->addProperty('id', 'unsigned');
15+
$this->expectException(Exception::class);
16+
17+
$space->addProperty('id', 'unsigned');
18+
}
19+
820
public function testRemoveProperty()
921
{
1022
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)