From c06d6d93fd3491b1482a890441a5a532e1bf6ce5 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 30 Mar 2016 14:03:24 -0500 Subject: [PATCH 1/3] Add Module::init to register the TranslatorPluginManager with the ServiceListener We need to register the TranslatorPluginManager with the ServiceListener, to allow modules and application configuration to provide additional plugin configuration. Since the ServiceListener is configured before modules are loaded, options for configuring it are limited. Adding delegator factories is out of the question, as that would require altering the application default services configuration, which is non-trivial. While this approach is slightly brittle -- if any modules are registered prior to it that have translator plugin configuration, that configuration will be ignored -- the goal is to have components registered before modules, which has some reasonable certainty of ensuring that the init() is called before any configuration is provided. --- phpunit.xml.dist | 2 +- src/Module.php | 19 ++++++++ test/ModuleTest.php | 49 +++++++++++++++++++++ test/TestAsset/ModuleEventInterface.php | 18 ++++++++ test/TestAsset/ServiceListenerInterface.php | 29 ++++++++++++ test/bootstrap.php | 34 -------------- 6 files changed, 116 insertions(+), 35 deletions(-) create mode 100644 test/ModuleTest.php create mode 100644 test/TestAsset/ModuleEventInterface.php create mode 100644 test/TestAsset/ServiceListenerInterface.php delete mode 100644 test/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bcff5816..e2d36766 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ diff --git a/src/Module.php b/src/Module.php index 29b622ed..3d1b5651 100644 --- a/src/Module.php +++ b/src/Module.php @@ -24,4 +24,23 @@ public function getConfig() 'view_helpers' => $provider->getViewHelperConfig(), ]; } + + /** + * Register a specification for the TranslatorPluginManager with the ServiceListener. + * + * @param \Zend\ModuleManager\ModuleEvent + * @return void + */ + public function init($event) + { + $container = $event->getParam('ServiceManager'); + $serviceListener = $container->get('ServiceListener'); + + $serviceListener->addServiceManager( + 'TranslatorPluginManager', + 'translator_plugins', + 'Zend\ModuleManager\Feature\TranslatorPluginProviderInterface', + 'getTranslatorPluginConfig' + ); + } } diff --git a/test/ModuleTest.php b/test/ModuleTest.php new file mode 100644 index 00000000..bd40e2a2 --- /dev/null +++ b/test/ModuleTest.php @@ -0,0 +1,49 @@ +module = new Module(); + } + + public function testConfigReturnsExpectedKeys() + { + $config = $this->module->getConfig(); + $this->assertInternalType('array', $config); + $this->assertArrayHasKey('filters', $config); + $this->assertArrayHasKey('service_manager', $config); + $this->assertArrayHasKey('validators', $config); + $this->assertArrayHasKey('view_helpers', $config); + } + + public function testInitRegistersPluginManagerSpecificationWithServiceListener() + { + $serviceListener = $this->prophesize(TestAsset\ServiceListenerInterface::class); + $serviceListener->addServiceManager( + 'TranslatorPluginManager', + 'translator_plugins', + 'Zend\ModuleManager\Feature\TranslatorPluginProviderInterface', + 'getTranslatorPluginConfig' + )->shouldBeCalled(); + + $container = $this->prophesize(ContainerInterface::class); + $container->get('ServiceListener')->willReturn($serviceListener->reveal()); + + $event = $this->prophesize(TestAsset\ModuleEventInterface::class); + $event->getParam('ServiceManager')->willReturn($container->reveal()); + + $this->assertNull($this->module->init($event->reveal())); + } +} diff --git a/test/TestAsset/ModuleEventInterface.php b/test/TestAsset/ModuleEventInterface.php new file mode 100644 index 00000000..cef63285 --- /dev/null +++ b/test/TestAsset/ModuleEventInterface.php @@ -0,0 +1,18 @@ + Date: Wed, 30 Mar 2016 14:16:29 -0500 Subject: [PATCH 2/3] Fixed travis-specific PHPUnit configuration --- phpunit.xml.travis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.travis b/phpunit.xml.travis index bcff5816..e2d36766 100644 --- a/phpunit.xml.travis +++ b/phpunit.xml.travis @@ -1,7 +1,7 @@ From 83d5cbf6b9ed94e5b4658bc5ff113d99f3feb324 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 30 Mar 2016 16:01:03 -0500 Subject: [PATCH 3/3] Added CHANGELOG for #41 --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 831198f4..de0cd21a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.7.1 - TBD +## 2.7.1 - 2016-03-30 ### Added -- Nothing. +- [#41](https://github.com/zendframework/zend-i18n/pull/41) adds + `Zend\I18n\Module::init()`, which registers a specification for the translator + loader plugin manager with `Zend\ModuleManager\Listener\ServiceListener`. ### Deprecated