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

Commit

Permalink
Merge pull request #52 from Maks3w/hotfix/merge-input-without-value
Browse files Browse the repository at this point in the history
Fix merge two inputs without value, result 'has value' flag should be false
  • Loading branch information
weierophinney committed Sep 2, 2015
2 parents ccef4bf + 74b9e5e commit 4f717eb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
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 @@ -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();
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

0 comments on commit 4f717eb

Please sign in to comment.