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

Commit b95619f

Browse files
committed
Merge branch 'hotfix/8-overwriting-chains-bug' into develop
Forward port #151
2 parents a60ecbb + 628b408 commit b95619f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39+
- [#151](https://github.com/zendframework/zend-inputfilter/pull/151) fixes an
40+
issue in `Factory::createInput()` introduced in
41+
[#2](https://github.com/zendframework/zend-inputfilter/pull/2) whereby an
42+
input pulled from the input filter manager would be injected with the default
43+
filter and validator chains, overwriting any chains that were set during
44+
instantiation and/or `init()`. They are now never overwritten.
45+
3946
- [#149](https://github.com/zendframework/zend-inputfilter/pull/149) fixes an
4047
issue with how error messages for collection input field items were reported;
4148
previously, as soon as one item in the collection failed, the same validation

src/Factory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ public function createInput($inputSpecification)
189189
));
190190
}
191191

192-
if ($this->defaultFilterChain) {
192+
if (! $managerInstance && $this->defaultFilterChain) {
193193
$input->setFilterChain(clone $this->defaultFilterChain);
194194
}
195-
if ($this->defaultValidatorChain) {
195+
if (! $managerInstance && $this->defaultValidatorChain) {
196196
$input->setValidatorChain(clone $this->defaultValidatorChain);
197197
}
198198

test/FactoryTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Interop\Container\ContainerInterface;
1313
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1414
use PHPUnit\Framework\TestCase;
15+
use Prophecy\Argument;
1516
use Zend\Filter;
1617
use Zend\InputFilter\CollectionInputFilter;
1718
use Zend\InputFilter\Exception\InvalidArgumentException;
@@ -996,6 +997,27 @@ public function testClearDefaultValidatorChain()
996997
$this->assertNull($factory->getDefaultValidatorChain());
997998
}
998999

1000+
/**
1001+
* @see https://github.com/zendframework/zend-inputfilter/issues/8
1002+
*/
1003+
public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains()
1004+
{
1005+
$input = $this->prophesize(InputInterface::class);
1006+
$input->setFilterChain(Argument::any())->shouldNotBeCalled();
1007+
$input->setValidatorChain(Argument::any())->shouldNotBeCalled();
1008+
1009+
$pluginManager = $this->prophesize(InputFilterPluginManager::class);
1010+
$pluginManager->populateFactoryPluginManagers(Argument::type(Factory::class))->shouldBeCalled();
1011+
$pluginManager->has('Some\Test\Input')->willReturn(true);
1012+
$pluginManager->get('Some\Test\Input')->will([$input, 'reveal']);
1013+
1014+
$spec = ['type' => 'Some\Test\Input'];
1015+
1016+
$factory = new Factory($pluginManager->reveal());
1017+
1018+
$this->assertSame($input->reveal(), $factory->createInput($spec));
1019+
}
1020+
9991021
/**
10001022
* @return Factory
10011023
*/

0 commit comments

Comments
 (0)