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

Commit dad31e9

Browse files
code quality improvements according to comments from code review
1 parent ce463ae commit dad31e9

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/Element/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function populateValues($data)
236236
}
237237
}
238238

239-
if ($elementOrFieldset) {
239+
if ($elementOrFieldset !== null) {
240240
if ($elementOrFieldset instanceof FieldsetInterface) {
241241
$elementOrFieldset->populateValues($value);
242242
} else {

test/Element/CollectionTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,20 +1403,34 @@ public function testTargetElementBeingNullNotCausingAnError()
14031403
{
14041404
$form = new Form();
14051405

1406-
$form->add([
1407-
'type' => 'Zend\Form\Element\Collection',
1408-
'name' => 'fieldsets',
1409-
'options' => [
1410-
'count' => 2
1406+
$form->add(
1407+
[
1408+
'type' => \Zend\Form\Element\Collection::class,
1409+
'name' => 'fieldsets',
1410+
'options' => [
1411+
'count' => 2
1412+
]
14111413
]
1412-
]);
1414+
);
14131415

14141416
$collection = $form->get('fieldsets');
1415-
$data = [];
1416-
$data['fieldsets'] = ['red', 'green', 'blue'];
1417+
$data = [
1418+
'fieldsets' => [
1419+
'red',
1420+
'green',
1421+
'blue'
1422+
]
1423+
];
14171424

1418-
$form->populateValues($data);
1425+
$form->setData($data);
1426+
$form->isValid();
14191427

1420-
$this->addToAssertionCount(1); // expect no exception being thrown
1428+
// expect the fieldsets key to be an empty array since there's no valid targetElement
1429+
$this->assertEquals(
1430+
[
1431+
'fieldsets' => []
1432+
],
1433+
$form->getData()
1434+
);
14211435
}
14221436
}

0 commit comments

Comments
 (0)