Skip to content

Commit 4ffc17a

Browse files
committed
implement removeProperty method
1 parent f527d38 commit 4ffc17a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Space.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ public function addProperty($name, $type)
3535
$this->parseFormat();
3636
}
3737

38+
public function removeProperty($name)
39+
{
40+
$format = $this->getFormat();
41+
$last = array_pop($format);
42+
if($last['name'] != $name) {
43+
throw new Exception("Remove only last property");
44+
}
45+
$this->mapper->getClient()->evaluate("box.space[$this->id]:format(...)", [$format]);
46+
$this->format = $format;
47+
48+
$this->parseFormat();
49+
}
50+
3851
public function removeIndex($name)
3952
{
4053
$this->mapper->getClient()->evaluate("box.space[$this->id].index.$name:drop()");

tests/SchemaTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
<?php
22

3-
use Exception;
43
use Tarantool\Mapper\Mapper;
54
use Tarantool\Mapper\Space;
65

76
class SchemaTest extends TestCase
87
{
8+
public function testRemoveProperty()
9+
{
10+
$mapper = $this->createMapper();
11+
$this->clean($mapper);
12+
13+
$space = $mapper->getSchema()->createSpace('tester');
14+
$space->addProperty('first', 'unsigned');
15+
$space->addProperty('second', 'unsigned');
16+
$space->addProperty('third', 'unsigned');
17+
18+
$this->assertCount(3, $space->getFormat());
19+
20+
$space->removeProperty('third');
21+
$this->assertCount(2, $space->getFormat());
22+
23+
$this->expectException(Exception::class);
24+
$space->removeIndex('first');
25+
}
26+
927
public function testRemoveIndex()
1028
{
1129
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)