Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
37 changes: 37 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @link http://github.com/zendframework/zend-mail for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Mail;

class ConfigProvider
{
/**
* Retrieve configuration for zend-mail package.
*
* @return array
*/
public function __invoke()
{
return [
'dependencies' => $this->getDependencyConfig(),
];
}

/**
* Retrieve dependency settings for zend-mail package.
*
* @return array
*/
public function getDependencyConfig()
{
return [
'factories' => [
Protocol\SmtpPluginManager::class => Protocol\SmtpPluginManagerFactory::class,
],
];
}
}
24 changes: 24 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @link http://github.com/zendframework/zend-mail for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Mail;

class Module
{
/**
* Retrieve zend-mail package configuration for zend-mvc context.
*
* @return array
*/
public function getConfig()
{
$provider = new ConfigProvider();
return [
'service_manager' => $provider->getDependencyConfig(),
];
}
}
2 changes: 1 addition & 1 deletion src/Protocol/SmtpPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SmtpPluginManager extends AbstractPluginManager
'zendmailprotocolsmtpauthcrammd5' => InvokableFactory::class,
'zendmailprotocolsmtpauthlogin' => InvokableFactory::class,
'zendmailprotocolsmtpauthplain' => InvokableFactory::class,
'zendmailprotocolsmtp' => InvokableFactory::class,
'zendmailprotocolsmtp' => InvokableFactory::class,
];

/**
Expand Down
53 changes: 53 additions & 0 deletions src/Protocol/SmtpPluginManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* @link http://github.com/zendframework/zend-mail for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Mail\Protocol;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class SmtpPluginManagerFactory implements FactoryInterface
{
/**
* zend-servicemanager v2 support for invocation options.
*
* @param array
*/
protected $creationOptions;

/**
* {@inheritDoc}
*
* @return SmtpPluginManager
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
return new SmtpPluginManager($container, $options ?: []);
}

/**
* {@inheritDoc}
*
* @return SmtpPluginManager
*/
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null)
{
return $this($container, $requestedName ?: SmtpPluginManager::class, $this->creationOptions);
}

/**
* zend-servicemanager v2 support for invocation options.
*
* @param array $options
* @return void
*/
public function setCreationOptions(array $options)
{
$this->creationOptions = $options;
}
}
73 changes: 73 additions & 0 deletions test/Protocol/SmtpPluginManagerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* @link http://github.com/zendframework/zend-mail for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Mail\Protocol;

use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Mail\Protocol\Smtp;
use Zend\Mail\Protocol\SmtpPluginManager;
use Zend\Mail\Protocol\SmtpPluginManagerFactory;
use Zend\ServiceManager\ServiceLocatorInterface;

class SmtpPluginManagerFactoryTest extends TestCase
{
public function testFactoryReturnsPluginManager()
{
$container = $this->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'));
}
}