From bfe504c5f5a4e6b4a689d19f4f6620d4ca51d27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=BChn?= Date: Tue, 6 Oct 2015 18:02:50 +0200 Subject: [PATCH 1/4] BaseInputFilter::populate() calls resetValue() for missing arrayinputs --- CHANGELOG.md | 2 +- src/BaseInputFilter.php | 2 +- test/BaseInputFilterTest.php | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cee927f0..e2383f3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- `ArrayInput::hasValue()` returned `true` for inputs that didn't get a value via `BaseInputFilter::setData()` ## 2.5.5 - 2015-09-03 diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 1fea9709..844a5957 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -513,7 +513,7 @@ protected function populate() } if ($input instanceof ArrayInput) { - $input->setValue([]); + $input->resetValue(); continue; } diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index 692adc93..a56916f7 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -565,8 +565,7 @@ public function testPopulateSupportsArrayInputEvenIfDataMissing() $arrayInput = $this->getMock(ArrayInput::class); $arrayInput ->expects($this->once()) - ->method('setValue') - ->with([]); + ->method('resetValue'); $filter = $this->inputFilter; $filter->add($arrayInput, 'arrayInput'); @@ -598,6 +597,15 @@ public function testMerge() ); } + public function testHasValueIsFalseIfNoValueWasProvided() + { + $inputFilter = new BaseInputFilter(); + $inputFilter->add(new ArrayInput(), 'foo'); + + $inputFilter->setData([]); + $this->assertFalse($inputFilter->get('foo')->hasValue()); + } + public function addMethodArgumentsProvider() { $inputTypes = $this->inputProvider(); From 04c174205a17ec3333ebc6428ff5324878d5de04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=BChn?= Date: Wed, 7 Oct 2015 09:34:04 +0200 Subject: [PATCH 2/4] removed redundant instanceof check ArrayInput is a child of Input so no need for an additional check of ArrayInput instance. --- src/BaseInputFilter.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 844a5957..5ccfdf44 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -512,11 +512,6 @@ protected function populate() continue; } - if ($input instanceof ArrayInput) { - $input->resetValue(); - continue; - } - if ($input instanceof Input) { $input->resetValue(); continue; From a816b144e21e2dc9be1ad468a3117bf3e572e1f1 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 8 Oct 2015 13:30:28 +0200 Subject: [PATCH 3/4] [#72] CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2383f3a..8f49d1d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- `ArrayInput::hasValue()` returned `true` for inputs that didn't get a value via `BaseInputFilter::setData()` +- [#72](https://github.com/zendframework/zend-inputfilter/pull/72) `ArrayInput` + value is properly reset after `BaseInputFilter::setData()` ## 2.5.5 - 2015-09-03 From 3ffd32c0862c879e72ff84cbfb259b817b6e5ea8 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 8 Oct 2015 13:34:23 +0200 Subject: [PATCH 4/4] [#72] Remove tests specific to ArrayInput on InputFilter suite ArrayInput specific logic branch its not longer present and current Input tests are enough --- test/BaseInputFilterTest.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index a56916f7..e55d9927 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -15,7 +15,6 @@ use PHPUnit_Framework_MockObject_MockObject as MockObject; use PHPUnit_Framework_TestCase as TestCase; use stdClass; -use Zend\InputFilter\ArrayInput; use Zend\InputFilter\BaseInputFilter; use Zend\InputFilter\Exception\InvalidArgumentException; use Zend\InputFilter\Exception\RuntimeException; @@ -556,22 +555,6 @@ public function testAddingExistingInputWillMergeIntoExisting() $this->assertFalse($filter->get('foo')->isRequired()); } - /** - * @group 5638 - */ - public function testPopulateSupportsArrayInputEvenIfDataMissing() - { - /** @var ArrayInput|MockObject $arrayInput */ - $arrayInput = $this->getMock(ArrayInput::class); - $arrayInput - ->expects($this->once()) - ->method('resetValue'); - - $filter = $this->inputFilter; - $filter->add($arrayInput, 'arrayInput'); - $filter->setData(['foo' => 'bar']); - } - /** * @group 6431 */ @@ -597,15 +580,6 @@ public function testMerge() ); } - public function testHasValueIsFalseIfNoValueWasProvided() - { - $inputFilter = new BaseInputFilter(); - $inputFilter->add(new ArrayInput(), 'foo'); - - $inputFilter->setData([]); - $this->assertFalse($inputFilter->get('foo')->hasValue()); - } - public function addMethodArgumentsProvider() { $inputTypes = $this->inputProvider();