Skip to content

Commit b3bdd0d

Browse files
committed
Add test for #315
1 parent 160096c commit b3bdd0d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/RelationsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,25 @@ public function testBelongsToManyAttachesExistingModels()
258258
$this->assertStringStartsWith('synced', $user->clients[1]->name);
259259
}
260260

261+
public function testBelongsToManySync()
262+
{
263+
// create test instances
264+
$user = User::create(array('name' => 'John Doe'));
265+
$client1 = Client::create(array('name' => 'Pork Pies Ltd.'))->_id;
266+
$client2 = Client::create(array('name' => 'Buffet Bar Inc.'))->_id;
267+
268+
// Sync multiple
269+
$user->clients()->sync(array($client1, $client2));
270+
$this->assertCount(2, $user->clients);
271+
272+
// Refresh user
273+
$user = User::where('name', '=', 'John Doe')->first();
274+
275+
// Sync single
276+
$user->clients()->sync(array($client1));
277+
$this->assertCount(1, $user->clients);
278+
}
279+
261280
public function testBelongsToManyCustom()
262281
{
263282
$user = User::create(array('name' => 'John Doe'));

0 commit comments

Comments
 (0)