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

Commit 4f717eb

Browse files
committed
Merge pull request #52 from Maks3w/hotfix/merge-input-without-value
Fix merge two inputs without value, result 'has value' flag should be false
2 parents ccef4bf + 74b9e5e commit 4f717eb

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

src/Input.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ public function merge(InputInterface $input)
368368
$this->setName($input->getName());
369369
$this->setRequired($input->isRequired());
370370
$this->setAllowEmpty($input->allowEmpty());
371-
$this->setValue($input->getRawValue());
371+
if (!($input instanceof Input) || $input->hasValue()) {
372+
$this->setValue($input->getRawValue());
373+
}
372374

373375
$filterChain = $input->getFilterChain();
374376
$this->getFilterChain()->merge($filterChain);

test/ArrayInputTest.php

-15
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,6 @@ public function testMerge($sourceRawValue = 'bazRawValue')
170170
parent::testMerge([$sourceRawValue]);
171171
}
172172

173-
public function testInputMerge()
174-
{
175-
$source = new Input();
176-
$source->setValue([]);
177-
$source->setContinueIfEmpty(true);
178-
179-
$target = $this->input;
180-
$target->setContinueIfEmpty(false);
181-
182-
$return = $target->merge($source);
183-
$this->assertSame($target, $return, 'merge() must return it self');
184-
185-
$this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match');
186-
}
187-
188173
public function fallbackValueVsIsValidProvider()
189174
{
190175
$dataSets = parent::fallbackValueVsIsValidProvider();

test/InputTest.php

+47-1
Original file line numberDiff line numberDiff line change
@@ -422,23 +422,69 @@ public function testMerge($sourceRawValue = 'bazRawValue')
422422
$this->assertEquals(true, $target->breakOnFailure(), 'breakOnFailure() value not match');
423423
$this->assertEquals(true, $target->isRequired(), 'isRequired() value not match');
424424
$this->assertEquals($sourceRawValue, $target->getRawValue(), 'getRawValue() value not match');
425+
$this->assertTrue($target->hasValue(), 'hasValue() value not match');
425426
}
426427

427428
/**
428429
* Specific Input::merge extras
429430
*/
430-
public function testInputMerge()
431+
public function testInputMergeWithoutValues()
431432
{
432433
$source = new Input();
433434
$source->setContinueIfEmpty(true);
435+
$this->assertFalse($source->hasValue(), 'Source should not have a value');
434436

435437
$target = $this->input;
436438
$target->setContinueIfEmpty(false);
439+
$this->assertFalse($target->hasValue(), 'Target should not have a value');
437440

438441
$return = $target->merge($source);
439442
$this->assertSame($target, $return, 'merge() must return it self');
440443

441444
$this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match');
445+
$this->assertFalse($target->hasValue(), 'hasValue() value not match');
446+
}
447+
448+
/**
449+
* Specific Input::merge extras
450+
*/
451+
public function testInputMergeWithSourceValue()
452+
{
453+
$source = new Input();
454+
$source->setContinueIfEmpty(true);
455+
$source->setValue(['foo']);
456+
457+
$target = $this->input;
458+
$target->setContinueIfEmpty(false);
459+
$this->assertFalse($target->hasValue(), 'Target should not have a value');
460+
461+
$return = $target->merge($source);
462+
$this->assertSame($target, $return, 'merge() must return it self');
463+
464+
$this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match');
465+
$this->assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match');
466+
$this->assertTrue($target->hasValue(), 'hasValue() value not match');
467+
}
468+
469+
/**
470+
* Specific Input::merge extras
471+
*/
472+
public function testInputMergeWithTargetValue()
473+
{
474+
$source = new Input();
475+
$source->setContinueIfEmpty(true);
476+
$this->assertFalse($source->hasValue(), 'Source should not have a value');
477+
478+
$target = $this->input;
479+
$target->setContinueIfEmpty(false);
480+
$target->setValue(['foo']);
481+
482+
$return = $target->merge($source);
483+
$this->assertSame($target, $return, 'merge() must return it self');
484+
485+
$this->assertEquals(true, $target->continueIfEmpty(), 'continueIfEmpty() value not match');
486+
$this->assertEquals(['foo'], $target->getRawValue(), 'getRawValue() value not match');
487+
$this->assertTrue($target->hasValue(), 'hasValue() value not match');
442488
}
443489

444490
public function fallbackValueVsIsValidProvider()

0 commit comments

Comments
 (0)