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

Commit

Permalink
Merge branch 'hotfix/131'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Nov 7, 2017
2 parents bc9e49b + d3818da commit 02bbc6b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## 2.7.5 - TBD
## 2.7.5 - 2017-11-07

### Added

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

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

## 2.7.4 - 2017-05-18

### Added
Expand Down
13 changes: 3 additions & 10 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,10 @@ public function setValidationGroup($name)

$inputs[] = $key;

if (! $this->inputs[$key] instanceof InputFilterInterface) {
throw new Exception\InvalidArgumentException(
sprintf(
'Input "%s" must implement InputFilterInterface',
$key
)
);
if ($this->inputs[$key] instanceof InputFilterInterface) {
// Recursively populate validation groups for sub input filters
$this->inputs[$key]->setValidationGroup($value);
}

// Recursively populate validation groups for sub input filters
$this->inputs[$key]->setValidationGroup($value);
}
} else {
$inputs = func_get_args();
Expand Down
27 changes: 24 additions & 3 deletions test/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,38 @@ public function testIsValidThrowExceptionIfDataWasNotSetYet()
$inputFilter->isValid();
}

public function testSetValidationGroupThrowExceptionIfInputIsNotAnInputFilter()
public function testSetValidationGroupSkipsRecursionWhenInputIsNotAnInputFilter()
{
$inputFilter = $this->inputFilter;

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

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Input "fooInput" must implement InputFilterInterface');
$inputFilter->setValidationGroup(['fooInput' => 'foo']);
$this->assertAttributeEquals(['fooInput'], 'validationGroup', $inputFilter);
}

public function testSetValidationGroupAllowsSpecifyingArrayOfInputsToNestedInputFilter()
{
$inputFilter = $this->inputFilter;

$nestedInputFilter = new BaseInputFilter();

/** @var InputInterface|MockObject $nestedInput1 */
$nestedInput1 = $this->createMock(InputInterface::class);
$nestedInputFilter->add($nestedInput1, 'nested-input1');

/** @var InputInterface|MockObject $nestedInput2 */
$nestedInput2 = $this->createMock(InputInterface::class);
$nestedInputFilter->add($nestedInput2, 'nested-input2');

$inputFilter->add($nestedInputFilter, 'nested');

$inputFilter->setValidationGroup(['nested' => ['nested-input1', 'nested-input2']]);

$this->assertAttributeEquals(['nested'], 'validationGroup', $inputFilter);
$this->assertAttributeEquals(['nested-input1', 'nested-input2'], 'validationGroup', $nestedInputFilter);
}

public function testSetValidationGroupThrowExceptionIfInputFilterNotExists()
Expand Down

0 comments on commit 02bbc6b

Please sign in to comment.