Skip to content

Commit

Permalink
Don't marshall non-array data.
Browse files Browse the repository at this point in the history
Non array data will never turn into entities, so we can skip it.

Refs #6271
  • Loading branch information
markstory committed Apr 24, 2015
1 parent acabf50 commit 29cfd3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ORM/Marshaller.php
Expand Up @@ -531,6 +531,9 @@ public function mergeMany($entities, array $data, array $options = [])
}

foreach ((new Collection($indexed))->append($new) as $value) {
if (!is_array($value)) {
continue;
}
$output[] = $this->one($value, $options);
}

Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -1512,6 +1512,32 @@ public function testMergeManySimple()
$this->assertFalse($result[1]->dirty('user_id'));
}

/**
* Test mergeMany() with some invalid data
*
* @return void
*/
public function testMergeManyInvalidData()
{
$entities = [
new OpenEntity(['id' => 1, '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' => 'Changed 1', 'user_id' => 1],
'_csrfToken' => 'abc123',
];
$marshall = new Marshaller($this->comments);
$result = $marshall->mergeMany($entities, $data);

$this->assertSame($entities[0], $result[0]);
$this->assertSame($entities[1], $result[1]);
}

/**
* Tests that only records found in the data array are returned, those that cannot
* be matched are discarded
Expand Down

0 comments on commit 29cfd3c

Please sign in to comment.