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/8-overwriting-chains-bug' into develop
Browse files Browse the repository at this point in the history
Forward port #151
  • Loading branch information
weierophinney committed Nov 7, 2017
2 parents a60ecbb + 628b408 commit b95619f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#151](https://github.com/zendframework/zend-inputfilter/pull/151) fixes an
issue in `Factory::createInput()` introduced in
[#2](https://github.com/zendframework/zend-inputfilter/pull/2) whereby an
input pulled from the input filter manager would be injected with the default
filter and validator chains, overwriting any chains that were set during
instantiation and/or `init()`. They are now never overwritten.

- [#149](https://github.com/zendframework/zend-inputfilter/pull/149) fixes an
issue with how error messages for collection input field items were reported;
previously, as soon as one item in the collection failed, the same validation
Expand Down
4 changes: 2 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public function createInput($inputSpecification)
));
}

if ($this->defaultFilterChain) {
if (! $managerInstance && $this->defaultFilterChain) {
$input->setFilterChain(clone $this->defaultFilterChain);
}
if ($this->defaultValidatorChain) {
if (! $managerInstance && $this->defaultValidatorChain) {
$input->setValidatorChain(clone $this->defaultValidatorChain);
}

Expand Down
22 changes: 22 additions & 0 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Interop\Container\ContainerInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Zend\Filter;
use Zend\InputFilter\CollectionInputFilter;
use Zend\InputFilter\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -996,6 +997,27 @@ public function testClearDefaultValidatorChain()
$this->assertNull($factory->getDefaultValidatorChain());
}

/**
* @see https://github.com/zendframework/zend-inputfilter/issues/8
*/
public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains()
{
$input = $this->prophesize(InputInterface::class);
$input->setFilterChain(Argument::any())->shouldNotBeCalled();
$input->setValidatorChain(Argument::any())->shouldNotBeCalled();

$pluginManager = $this->prophesize(InputFilterPluginManager::class);
$pluginManager->populateFactoryPluginManagers(Argument::type(Factory::class))->shouldBeCalled();
$pluginManager->has('Some\Test\Input')->willReturn(true);
$pluginManager->get('Some\Test\Input')->will([$input, 'reveal']);

$spec = ['type' => 'Some\Test\Input'];

$factory = new Factory($pluginManager->reveal());

$this->assertSame($input->reveal(), $factory->createInput($spec));
}

/**
* @return Factory
*/
Expand Down

0 comments on commit b95619f

Please sign in to comment.