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

Fix merge two inputs without value, result 'has value' flag should be false #52

Merged
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
4 changes: 3 additions & 1 deletion src/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 0 additions & 15 deletions test/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,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();
Expand Down
48 changes: 47 additions & 1 deletion test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down