diff --git a/src/Input.php b/src/Input.php index 2eda11ee..cc3750ef 100644 --- a/src/Input.php +++ b/src/Input.php @@ -368,7 +368,9 @@ public function merge(InputInterface $input) $this->setName($input->getName()); $this->setRequired($input->isRequired()); $this->setAllowEmpty($input->allowEmpty()); - $this->setValue($input->getRawValue()); + if (!($input instanceof Input) || $input->hasValue()) { + $this->setValue($input->getRawValue()); + } $filterChain = $input->getFilterChain(); $this->getFilterChain()->merge($filterChain); diff --git a/test/ArrayInputTest.php b/test/ArrayInputTest.php index cded0ef0..bdba8db3 100644 --- a/test/ArrayInputTest.php +++ b/test/ArrayInputTest.php @@ -170,21 +170,6 @@ public function testMerge($sourceRawValue = 'bazRawValue') parent::testMerge([$sourceRawValue]); } - public function testInputMerge() - { - $source = new Input(); - $source->setValue([]); - $source->setContinueIfEmpty(true); - - $target = $this->input; - $target->setContinueIfEmpty(false); - - $return = $target->merge($source); - $this->assertSame($target, $return, 'merge() must return it self'); - - $this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match'); - } - public function fallbackValueVsIsValidProvider() { $dataSets = parent::fallbackValueVsIsValidProvider(); diff --git a/test/InputTest.php b/test/InputTest.php index 2ac49c53..94cac668 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -422,23 +422,69 @@ public function testMerge($sourceRawValue = 'bazRawValue') $this->assertEquals(true, $target->breakOnFailure(), 'breakOnFailure() value not match'); $this->assertEquals(true, $target->isRequired(), 'isRequired() value not match'); $this->assertEquals($sourceRawValue, $target->getRawValue(), 'getRawValue() value not match'); + $this->assertTrue($target->hasValue(), 'hasValue() value not match'); } /** * Specific Input::merge extras */ - public function testInputMerge() + public function testInputMergeWithoutValues() { $source = new Input(); $source->setContinueIfEmpty(true); + $this->assertFalse($source->hasValue(), 'Source should not have a value'); $target = $this->input; $target->setContinueIfEmpty(false); + $this->assertFalse($target->hasValue(), 'Target should not have a value'); $return = $target->merge($source); $this->assertSame($target, $return, 'merge() must return it self'); $this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match'); + $this->assertFalse($target->hasValue(), 'hasValue() value not match'); + } + + /** + * Specific Input::merge extras + */ + public function testInputMergeWithSourceValue() + { + $source = new Input(); + $source->setContinueIfEmpty(true); + $source->setValue(['foo']); + + $target = $this->input; + $target->setContinueIfEmpty(false); + $this->assertFalse($target->hasValue(), 'Target should not have a value'); + + $return = $target->merge($source); + $this->assertSame($target, $return, 'merge() must return it self'); + + $this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match'); + $this->assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match'); + $this->assertTrue($target->hasValue(), 'hasValue() value not match'); + } + + /** + * Specific Input::merge extras + */ + public function testInputMergeWithTargetValue() + { + $source = new Input(); + $source->setContinueIfEmpty(true); + $this->assertFalse($source->hasValue(), 'Source should not have a value'); + + $target = $this->input; + $target->setContinueIfEmpty(false); + $target->setValue(['foo']); + + $return = $target->merge($source); + $this->assertSame($target, $return, 'merge() must return it self'); + + $this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match'); + $this->assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match'); + $this->assertTrue($target->hasValue(), 'hasValue() value not match'); } public function fallbackValueVsIsValidProvider()