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

Commit bc9e49b

Browse files
committed
Merge branch 'hotfix/8-overwriting-chains-bug'
Close #151 Fixes #8
2 parents 913ff6a + 628b408 commit bc9e49b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21+
- [#151](https://github.com/zendframework/zend-inputfilter/pull/151) fixes an
22+
issue in `Factory::createInput()` introduced in
23+
[#2](https://github.com/zendframework/zend-inputfilter/pull/2) whereby an
24+
input pulled from the input filter manager would be injected with the default
25+
filter and validator chains, overwriting any chains that were set during
26+
instantiation and/or `init()`. They are now never overwritten.
27+
2128
- [#149](https://github.com/zendframework/zend-inputfilter/pull/149) fixes an
2229
issue with how error messages for collection input field items were reported;
2330
previously, as soon as one item in the collection failed, the same validation

src/Factory.php

Lines changed: 2 additions & 2 deletions
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

Lines changed: 22 additions & 0 deletions
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)