Skip to content
Permalink
Browse files

Implementing the fieldList option in the merge() method

  • Loading branch information...
lorenzo committed Jul 11, 2014
1 parent f62cad5 commit 00b9d098d2ab1c0536337251b93a41b23c6148b5
Showing with 43 additions and 1 deletion.
  1. +11 −1 src/ORM/Marshaller.php
  2. +32 −0 tests/TestCase/ORM/MarshallerTest.php
@@ -280,7 +280,17 @@ public function merge(EntityInterface $entity, array $data, array $options = [])
$properties[$key] = $value;
}
$entity->set($properties);
if (!isset($options['fieldList'])) {
$entity->set($properties);
return $entity;
}
foreach ((array)$options['fieldList'] as $field) {
if (isset($properties[$field])) {
$entity->set($field, $properties[$field]);
}
}
return $entity;
}
@@ -1000,4 +1000,36 @@ public function testOneWithFieldList() {
$this->assertEquals($data, $result->toArray());
}
/**
* Tests that it is possible to pass a fieldList option to the merge method
*
* @return void
*/
public function testMergeWithFieldList() {
$data = [
'title' => 'My title',
'author_id' => 1
];
$marshall = new Marshaller($this->articles);
$entity = new Entity([
'title' => 'Foo',
'body' => 'My Content',
'author_id' => 2
]);
$entity->accessible('*', false);
$entity->isNew(false);
$entity->clean();
$result = $marshall->merge($entity, $data, ['fieldList' => ['title', 'body']]);
$expected = [
'title' => 'My title',
'body' => 'My Content',
'author_id' => 2
];
$this->assertSame($entity, $result);
$this->assertEquals($expected, $result->toArray());
$this->assertFalse($entity->accessible('*'));
}
}

0 comments on commit 00b9d09

Please sign in to comment.
You can’t perform that action at this time.