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

Commit

Permalink
Ensure input filter plugin manager is BC with v2
Browse files Browse the repository at this point in the history
- Renamed `MigrationTest` to `InputFilterPluginManagerCompatibilityTest`
  (consistency with other components, and this is specifically for
  testing migration of the plugin manager).
- Added tests to validate that the `InputFilterPluginManager` accepts no
  arguments and/or a `ConfigInterface` argument to the constructor when
  using zend-servicemanager v2.
- Updated the `InputFilterPluginManager` constructor to mirror that of
  the 2.7 and 3.0 series of zend-servicemanager; it also populates the
  initializers prior to calling the parent constructor, allowing
  overriding.
  • Loading branch information
weierophinney committed Feb 18, 2016
1 parent ec011db commit 41c30e2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/InputFilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ class InputFilterPluginManager extends AbstractPluginManager
*/
protected $shareByDefault = false;


/**
* @param ContainerInterface $parentLocator
* @param array $config
* @param null|\Zend\ServiceManager\ConfigInterface|ContainerInterface $configOrContainer
* For zend-servicemanager v2, null or a ConfigInterface instance are
* allowed; for v3, a ContainerInterface is expected.
* @param array $v3config Optional configuration array (zend-servicemanager v3 only)
*/
public function __construct(ContainerInterface $parentLocator, array $config = [])
public function __construct($configOrContainer = null, array $v3config = [])
{
parent::__construct($parentLocator, $config);
$this->addInitializer([$this, 'populateFactory']);
$this->initializers[] = [$this, 'populateFactory'];
parent::__construct($configOrContainer, $v3config);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
use PHPUnit_Framework_TestCase as TestCase;
use Zend\InputFilter\Exception\RuntimeException;
use Zend\InputFilter\InputFilterPluginManager;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Test\CommonPluginManagerTrait;

class MigrationTest extends TestCase
class InputFilterPluginManagerCompatibilityTest extends TestCase
{
use CommonPluginManagerTrait;

Expand All @@ -39,4 +40,26 @@ protected function getInstanceOf()
// InputFilterManager accepts multiple instance types
return;
}

public function testConstructorArgumentsAreOptionalUnderV2()
{
$plugins = $this->getPluginManager();
if (method_exists($plugins, 'configure')) {
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
}

$plugins = new InputFilterPluginManager();
$this->assertInstanceOf(InputFilterPluginManager::class, $plugins);
}

public function testConstructorAllowsConfigInstanceAsFirstArgumentUnderV2()
{
$plugins = $this->getPluginManager();
if (method_exists($plugins, 'configure')) {
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
}

$plugins = new InputFilterPluginManager(new Config([]));
$this->assertInstanceOf(InputFilterPluginManager::class, $plugins);
}
}

0 comments on commit 41c30e2

Please sign in to comment.