Skip to content

Commit

Permalink
Merge pull request #19 from atlasphp/issue-16-test
Browse files Browse the repository at this point in the history
add test for #16
  • Loading branch information
pmjones authored May 10, 2021
2 parents 2ef750a + a9d5a3e commit f495c32
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Relationship/OneToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ public function persistForeign(
foreach ($foreignRecordSet as $foreignRecord) {
$foreignMapper->persist($foreignRecord, $tracker);
}

$foreignRecordSet->detachDeleted();
}
}
33 changes: 33 additions & 0 deletions tests/Relationship/ManyToManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function testForeignPersist_basic()
->select()
->fetchRecordSet();

// make sure there are three taggings and tags
$this->assertCount(3, $before->tags);
$this->assertCount(3, $before->taggings);

// remove tag 'foo'
$before->tags->detachOneBy(['name' => 'foo']);

Expand All @@ -35,6 +39,10 @@ public function testForeignPersist_basic()
// persist it
$threadMapper->persist($before);

// make sure the taggings are detached properly
$this->assertCount(3, $before->tags);
$this->assertCount(3, $before->taggings);

// re-get the thread, with new taggings
$after = $threadMapper->fetchRecord(1, [
'tags'
Expand Down Expand Up @@ -132,6 +140,31 @@ public function testForeignPersist_allNew()
$this->assertEquals($expect, $actual);
}

public function testForeignPersist_detachAll()
{
$threadMapper = $this->mapperLocator->get(Thread::CLASS);

$before = $threadMapper->fetchRecord(1, [
'tags'
]);

$this->assertCount(3, $before->taggings);
$this->assertCount(3, $before->tags);

$before->tags->detachAll();
$threadMapper->persist($before);

$this->assertCount(0, $before->tags);
$this->assertCount(0, $before->taggings);

$after = $threadMapper->fetchRecord(1, [
'tags'
]);

$this->assertCount(0, $after->taggings);
$this->assertCount(0, $after->tags);
}

public function testJoinSelect()
{
$actual = $this->mapperLocator->get(Thread::CLASS)
Expand Down

0 comments on commit f495c32

Please sign in to comment.