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

Commit

Permalink
[zendframework/zendframework#4996] Correct order of merging
Browse files Browse the repository at this point in the history
- Added test showing issue with merging
- Fixed merging logic to merge new input with old
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ public function add($input, $name = null)
}

if (isset($this->inputs[$name]) && $this->inputs[$name] instanceof InputInterface) {
// The element already exists, so merge the config. Please note that the order is important (already existing
// The element already exists, so merge the config. Please note
// that the order is important (already existing
// input is merged with the parameter given)
$input->merge($this->inputs[$name]);
$original = $this->inputs[$name];
$original->merge($input);
return $this;
}

$this->inputs[$name] = $input;
Expand Down
18 changes: 18 additions & 0 deletions test/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,4 +765,22 @@ public function testGetInputs()
$this->assertEquals('foo', $filters['foo']->getName());
$this->assertEquals('bar', $filters['bar']->getName());
}

/**
* @group 4996
*/
public function testAddingExistingInputWillMergeIntoExisting()
{
$filter = new InputFilter();

$foo1 = new Input('foo');
$foo1->setRequired(true);
$filter->add($foo1);

$foo2 = new Input('foo');
$foo2->setRequired(false);
$filter->add($foo2);

$this->assertFalse($filter->get('foo')->isRequired());
}
}

0 comments on commit 6392db0

Please sign in to comment.