Skip to content

Commit 6c15a2e

Browse files
committed
entity.sync shortcut
1 parent cc5af74 commit 6c15a2e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Entity.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public function __call($name, $arguments)
6464
throw new BadMethodCallException("Call to undefined method ". get_class($this).'::'.$name);
6565
}
6666

67+
public function sync() : Entity
68+
{
69+
return $this->getRepository()->sync($this->id);
70+
}
71+
6772
public function __debugInfo()
6873
{
6974
$info = get_object_vars($this);

tests/MapperTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Tarantool\Client\Client;
55
use Tarantool\Client\Middleware\FirewallMiddleware;
66
use Tarantool\Client\Middleware\LoggingMiddleware;
7+
use Tarantool\Client\Schema\Operations;
78
use Tarantool\Client\Request\InsertRequest;
89
use Tarantool\Mapper\Mapper;
910
use Tarantool\Mapper\Plugin\Sequence;
@@ -13,6 +14,29 @@
1314

1415
class MapperTest extends TestCase
1516
{
17+
public function testSync()
18+
{
19+
$mapper = $this->createMapper();
20+
$mapper->getPlugin(new Sequence($mapper));
21+
$this->clean($mapper);
22+
23+
$mapper->getSchema()
24+
->createSpace('post')
25+
->addProperty('id', 'unsigned')
26+
->addProperty('title', 'string')
27+
->addProperty('slug', 'string')
28+
->addIndex('id')
29+
->addIndex('slug');
30+
31+
$post = $mapper->create('post', ['title' => 'hello']);
32+
33+
$this->assertSame("", $post->slug);
34+
$mapper->getClient()->getSpace('post')->update([$post->id], Operations::set(2, 'hello'));
35+
$this->assertSame("", $post->slug);
36+
$post->sync();
37+
$this->assertSame("hello", $post->slug);
38+
}
39+
1640
public function testVinylEngine()
1741
{
1842
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)