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

Commit

Permalink
Do not re-inject filter/validator chains of inputs pulled from plugin…
Browse files Browse the repository at this point in the history
… manager

As reported in #8, a change in #2 now causes inputs pulled from the
plugin manager within `Factory::createInput()` to be injected with the
default filter and validator chains composed in the `Factory`.
This can cause filter and validator chains created during construction
or within the input's factory to be overwritten entirely.

This patch adds conditions to skip injection of the default filter and
validator chains on inputs pulled from the input filter manager, while
retaining the logic introduced in #2 to allow values in the
`$inputSpecification` to further configure the instance.
  • Loading branch information
weierophinney committed Nov 7, 2017
1 parent 913ff6a commit a89aec2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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 a89aec2

Please sign in to comment.