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

Commit 767ed40

Browse files
committed
Merge branch 'hotfix/14'
Close #14
2 parents 2eeeae1 + 733f413 commit 767ed40

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#14](https://github.com/zendframework/zend-form/pull/14) ensures that
22+
collections can remove all elements when populating values.
2223

2324
## 2.6.0 - 2015-09-22
2425

src/Element/Collection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ public function populateValues($data)
195195
));
196196
}
197197

198-
// Can't do anything with empty data
199-
if (empty($data)) {
200-
return;
201-
}
202-
203198
if (!$this->allowRemove && count($data) < $this->count) {
204199
throw new Exception\DomainException(sprintf(
205200
'There are fewer elements than specified in the collection (%s). Either set the allow_remove option '

test/Element/CollectionTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,11 +938,15 @@ public function testCanRemoveAllElementsIfAllowRemoveIsTrue()
938938
$collection->setAllowRemove(true);
939939
$collection->setCount(0);
940940

941-
942941
// By default, $collection contains 2 elements
943942
$data = [];
943+
$data[] = 'blue';
944+
$data[] = 'green';
944945

945946
$collection->populateValues($data);
947+
$this->assertEquals(2, count($collection->getElements()));
948+
949+
$collection->populateValues([]);
946950
$this->assertEquals(0, count($collection->getElements()));
947951
}
948952

@@ -1233,14 +1237,14 @@ public function testCollectionShouldSilentlyIgnorePopulatingFieldsetWithDisallow
12331237
public function testCanHydrateObject()
12341238
{
12351239
$form = $this->form;
1240+
$object = new \ArrayObject();
1241+
$form->bind($object);
12361242
$data = [
12371243
'colors' => [
12381244
'#ffffff',
12391245
],
12401246
];
12411247
$form->setData($data);
1242-
$object = new \ArrayObject();
1243-
$form->bind($object);
12441248
$this->assertTrue($form->isValid());
12451249
$this->assertInternalType('array', $object['colors']);
12461250
$this->assertCount(1, $object['colors']);

0 commit comments

Comments
 (0)