diff --git a/composer.json b/composer.json index 4275fdfd..47b2f9c4 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,10 @@ "branch-alias": { "dev-master": "2.6-dev", "dev-develop": "2.7-dev" + }, + "zf": { + "component": "Zend\\Mail", + "config-provider": "Zend\\Mail\\ConfigProvider" } }, "autoload-dev": { diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php new file mode 100644 index 00000000..06d3b6f0 --- /dev/null +++ b/src/ConfigProvider.php @@ -0,0 +1,37 @@ + $this->getDependencyConfig(), + ]; + } + + /** + * Retrieve dependency settings for zend-mail package. + * + * @return array + */ + public function getDependencyConfig() + { + return [ + 'factories' => [ + Protocol\SmtpPluginManager::class => Protocol\SmtpPluginManagerFactory::class, + ], + ]; + } +} diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 00000000..2ad6674d --- /dev/null +++ b/src/Module.php @@ -0,0 +1,24 @@ + $provider->getDependencyConfig(), + ]; + } +} diff --git a/src/Protocol/SmtpPluginManager.php b/src/Protocol/SmtpPluginManager.php index a03ec7c9..c0160361 100644 --- a/src/Protocol/SmtpPluginManager.php +++ b/src/Protocol/SmtpPluginManager.php @@ -55,7 +55,7 @@ class SmtpPluginManager extends AbstractPluginManager 'zendmailprotocolsmtpauthcrammd5' => InvokableFactory::class, 'zendmailprotocolsmtpauthlogin' => InvokableFactory::class, 'zendmailprotocolsmtpauthplain' => InvokableFactory::class, - 'zendmailprotocolsmtp' => InvokableFactory::class, + 'zendmailprotocolsmtp' => InvokableFactory::class, ]; /** diff --git a/src/Protocol/SmtpPluginManagerFactory.php b/src/Protocol/SmtpPluginManagerFactory.php new file mode 100644 index 00000000..be10a96a --- /dev/null +++ b/src/Protocol/SmtpPluginManagerFactory.php @@ -0,0 +1,53 @@ +creationOptions); + } + + /** + * zend-servicemanager v2 support for invocation options. + * + * @param array $options + * @return void + */ + public function setCreationOptions(array $options) + { + $this->creationOptions = $options; + } +} diff --git a/test/Protocol/SmtpPluginManagerFactoryTest.php b/test/Protocol/SmtpPluginManagerFactoryTest.php new file mode 100644 index 00000000..145bd52f --- /dev/null +++ b/test/Protocol/SmtpPluginManagerFactoryTest.php @@ -0,0 +1,73 @@ +prophesize(ContainerInterface::class)->reveal(); + $factory = new SmtpPluginManagerFactory(); + + $plugins = $factory($container, SmtpPluginManager::class); + $this->assertInstanceOf(SmtpPluginManager::class, $plugins); + + if (method_exists($plugins, 'configure')) { + // zend-servicemanager v3 + $this->assertAttributeSame($container, 'creationContext', $plugins); + } else { + // zend-servicemanager v2 + $this->assertSame($container, $plugins->getServiceLocator()); + } + } + + /** + * @depends testFactoryReturnsPluginManager + */ + public function testFactoryConfiguresPluginManagerUnderContainerInterop() + { + $container = $this->prophesize(ContainerInterface::class)->reveal(); + $smtp = $this->prophesize(Smtp::class)->reveal(); + + $factory = new SmtpPluginManagerFactory(); + $plugins = $factory($container, SmtpPluginManager::class, [ + 'services' => [ + 'test' => $smtp, + ], + ]); + $this->assertSame($smtp, $plugins->get('test')); + } + + /** + * @depends testFactoryReturnsPluginManager + */ + public function testFactoryConfiguresPluginManagerUnderServiceManagerV2() + { + $container = $this->prophesize(ServiceLocatorInterface::class); + $container->willImplement(ContainerInterface::class); + + $smtp = $this->prophesize(Smtp::class)->reveal(); + + $factory = new SmtpPluginManagerFactory(); + $factory->setCreationOptions([ + 'services' => [ + 'test' => $smtp, + ], + ]); + + $plugins = $factory->createService($container->reveal()); + $this->assertSame($smtp, $plugins->get('test')); + } +}