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

Commit 02bbc6b

Browse files
committed
Merge branch 'hotfix/131'
Close #131 Fixes zendframework/zendframework#7760
2 parents bc9e49b + d3818da commit 02bbc6b

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.7.5 - TBD
5+
## 2.7.5 - 2017-11-07
66

77
### Added
88

@@ -30,6 +30,14 @@ All notable changes to this project will be documented in this file, in reverse
3030
previously, as soon as one item in the collection failed, the same validation
3131
message was propagated to all other items. This is now resolved.
3232

33+
- [#131](https://github.com/zendframework/zend-inputfilter/pull/131) fixes a
34+
regression introduced in version 2.2.6 within
35+
`BaseInputFilter::setValidatorGroup()` whereby it began emitting exceptions if
36+
a given input was not an input filter. This raises issues when mixing input
37+
filters and inputs in the same validator group specification, as you will
38+
generally provide the input names as keys instead of values. The patch provide
39+
ensures both styles work going forwards.
40+
3341
## 2.7.4 - 2017-05-18
3442

3543
### Added

src/BaseInputFilter.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,10 @@ public function setValidationGroup($name)
309309

310310
$inputs[] = $key;
311311

312-
if (! $this->inputs[$key] instanceof InputFilterInterface) {
313-
throw new Exception\InvalidArgumentException(
314-
sprintf(
315-
'Input "%s" must implement InputFilterInterface',
316-
$key
317-
)
318-
);
312+
if ($this->inputs[$key] instanceof InputFilterInterface) {
313+
// Recursively populate validation groups for sub input filters
314+
$this->inputs[$key]->setValidationGroup($value);
319315
}
320-
321-
// Recursively populate validation groups for sub input filters
322-
$this->inputs[$key]->setValidationGroup($value);
323316
}
324317
} else {
325318
$inputs = func_get_args();

test/BaseInputFilterTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,38 @@ public function testIsValidThrowExceptionIfDataWasNotSetYet()
125125
$inputFilter->isValid();
126126
}
127127

128-
public function testSetValidationGroupThrowExceptionIfInputIsNotAnInputFilter()
128+
public function testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter()
129129
{
130130
$inputFilter = $this->inputFilter;
131131

132132
/** @var InputInterface|MockObject $nestedInput */
133133
$nestedInput = $this->createMock(InputInterface::class);
134134
$inputFilter->add($nestedInput, 'fooInput');
135135

136-
$this->expectException(InvalidArgumentException::class);
137-
$this->expectExceptionMessage('Input "fooInput" must implement InputFilterInterface');
138136
$inputFilter->setValidationGroup(['fooInput' => 'foo']);
137+
$this->assertAttributeEquals(['fooInput'], 'validationGroup', $inputFilter);
138+
}
139+
140+
public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInputFilter()
141+
{
142+
$inputFilter = $this->inputFilter;
143+
144+
$nestedInputFilter = new BaseInputFilter();
145+
146+
/** @var InputInterface|MockObject $nestedInput1 */
147+
$nestedInput1 = $this->createMock(InputInterface::class);
148+
$nestedInputFilter->add($nestedInput1, 'nested-input1');
149+
150+
/** @var InputInterface|MockObject $nestedInput2 */
151+
$nestedInput2 = $this->createMock(InputInterface::class);
152+
$nestedInputFilter->add($nestedInput2, 'nested-input2');
153+
154+
$inputFilter->add($nestedInputFilter, 'nested');
155+
156+
$inputFilter->setValidationGroup(['nested' => ['nested-input1', 'nested-input2']]);
157+
158+
$this->assertAttributeEquals(['nested'], 'validationGroup', $inputFilter);
159+
$this->assertAttributeEquals(['nested-input1', 'nested-input2'], 'validationGroup', $nestedInputFilter);
139160
}
140161

141162
public function testSetValidationGroupThrowExceptionIfInputFilterNotExists()

0 commit comments

Comments
 (0)