Permalink
Browse files

Added tests to show how mergeMany discards unmatched records

  • Loading branch information...
1 parent 6c131a6 commit 2164100a11bf05c9ac2b2a1ef49d6ad4267b2b6b @lorenzo lorenzo committed Mar 2, 2014
Showing with 29 additions and 0 deletions.
  1. +29 −0 tests/TestCase/ORM/MarshallerTest.php
@@ -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.