From 41c30e20d3b770693434e9bfaa1ed409194cb061 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 18 Feb 2016 13:17:17 -0600 Subject: [PATCH] Ensure input filter plugin manager is BC with v2 - 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. --- src/InputFilterPluginManager.php | 13 +++++----- ...tFilterPluginManagerCompatibilityTest.php} | 25 ++++++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) rename test/{MigrationTest.php => InputFilterPluginManagerCompatibilityTest.php} (53%) diff --git a/src/InputFilterPluginManager.php b/src/InputFilterPluginManager.php index a658260d..b2c8daf4 100644 --- a/src/InputFilterPluginManager.php +++ b/src/InputFilterPluginManager.php @@ -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); } /** diff --git a/test/MigrationTest.php b/test/InputFilterPluginManagerCompatibilityTest.php similarity index 53% rename from test/MigrationTest.php rename to test/InputFilterPluginManagerCompatibilityTest.php index b91e332f..32de3fb2 100644 --- a/test/MigrationTest.php +++ b/test/InputFilterPluginManagerCompatibilityTest.php @@ -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; @@ -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); + } }