Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
code quality improvements according to comments from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
werequireevenmoreminerals committed Feb 21, 2019
1 parent ce463ae commit dad31e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Element/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function populateValues($data)
}
}

if ($elementOrFieldset) {
if ($elementOrFieldset !== null) {
if ($elementOrFieldset instanceof FieldsetInterface) {
$elementOrFieldset->populateValues($value);
} else {
Expand Down
34 changes: 24 additions & 10 deletions test/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1403,20 +1403,34 @@ public function testTargetElementBeingNullNotCausingAnError()
{
$form = new Form();

$form->add([
'type' => 'Zend\Form\Element\Collection',
'name' => 'fieldsets',
'options' => [
'count' => 2
$form->add(
[
'type' => \Zend\Form\Element\Collection::class,
'name' => 'fieldsets',
'options' => [
'count' => 2
]
]
]);
);

$collection = $form->get('fieldsets');
$data = [];
$data['fieldsets'] = ['red', 'green', 'blue'];
$data = [
'fieldsets' => [
'red',
'green',
'blue'
]
];

$form->populateValues($data);
$form->setData($data);
$form->isValid();

$this->addToAssertionCount(1); // expect no exception being thrown
// expect the fieldsets key to be an empty array since there's no valid targetElement
$this->assertEquals(
[
'fieldsets' => []
],
$form->getData()
);
}
}

0 comments on commit dad31e9

Please sign in to comment.