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

it's impossible to remove all elements from collection #14

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/Element/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ public function populateValues($data)
));
}

// Can't do anything with empty data
if (empty($data)) {
return;
}

if (!$this->allowRemove && count($data) < $this->count) {
throw new Exception\DomainException(sprintf(
'There are fewer elements than specified in the collection (%s). Either set the allow_remove option '
Expand Down
10 changes: 7 additions & 3 deletions test/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,15 @@ public function testCanRemoveAllElementsIfAllowRemoveIsTrue()
$collection->setAllowRemove(true);
$collection->setCount(0);


// By default, $collection contains 2 elements
$data = [];
$data[] = 'blue';
$data[] = 'green';

$collection->populateValues($data);
$this->assertEquals(2, count($collection->getElements()));

$collection->populateValues([]);
$this->assertEquals(0, count($collection->getElements()));
}

Expand Down Expand Up @@ -1233,14 +1237,14 @@ public function testCollectionShouldSilentlyIgnorePopulatingFieldsetWithDisallow
public function testCanHydrateObject()
{
$form = $this->form;
$object = new \ArrayObject();
$form->bind($object);
$data = [
'colors' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these test changes have to do with the change you're introducing? If they're unrelated, please revert them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weierophinney it is related only because it was not failing just because collection can't remove all elements that's what this PR fixes so it needs to be fixed also.

'#ffffff',
],
];
$form->setData($data);
$object = new \ArrayObject();
$form->bind($object);
$this->assertTrue($form->isValid());
$this->assertInternalType('array', $object['colors']);
$this->assertCount(1, $object['colors']);
Expand Down