Skip to content

Commit

Permalink
Added tests to show how mergeMany discards unmatched records
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 2, 2014
1 parent 6c131a6 commit 2164100
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/TestCase/ORM/MarshallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,33 @@ public function testMergeManySimple() {
$this->assertFalse($result[1]->dirty('user_id'));
}

/**
* Tests that only records found in the data array are returned, those that cannot
* be matched are discarded
*
* @return void
*/
public function testMergeManyWithAppend() {
$entities = [
new OpenEntity(['comment' => 'First post', 'user_id' => 2]),
new OpenEntity(['id' => 2, 'comment' => 'Second post', 'user_id' => 2])
];
$entities[0]->clean();
$entities[1]->clean();

$data = [
['id' => 2, 'comment' => 'Changed 2', 'user_id' => 2],
['id' => 1, 'comment' => 'Comment 1', 'user_id' => 1]
];
$marshall = new Marshaller($this->comments);
$result = $marshall->mergeMany($entities, $data);

$this->assertCount(2, $result);
$this->assertNotSame($entities[0], $result[0]);
$this->assertSame($entities[1], $result[0]);
$this->assertEquals('Changed 2', $result[0]->comment);

}


}

0 comments on commit 2164100

Please sign in to comment.