|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @link http://github.com/zendframework/zend-mail for the canonical source repository |
| 4 | + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) |
| 5 | + * @license http://framework.zend.com/license/new-bsd New BSD License |
| 6 | + */ |
| 7 | + |
| 8 | +namespace ZendTest\Mail\Protocol; |
| 9 | + |
| 10 | +use Interop\Container\ContainerInterface; |
| 11 | +use PHPUnit_Framework_TestCase as TestCase; |
| 12 | +use Zend\Mail\Protocol\Smtp; |
| 13 | +use Zend\Mail\Protocol\SmtpPluginManager; |
| 14 | +use Zend\Mail\Protocol\SmtpPluginManagerFactory; |
| 15 | +use Zend\ServiceManager\ServiceLocatorInterface; |
| 16 | + |
| 17 | +class SmtpPluginManagerFactoryTest extends TestCase |
| 18 | +{ |
| 19 | + public function testFactoryReturnsPluginManager() |
| 20 | + { |
| 21 | + $container = $this->prophesize(ContainerInterface::class)->reveal(); |
| 22 | + $factory = new SmtpPluginManagerFactory(); |
| 23 | + |
| 24 | + $plugins = $factory($container, SmtpPluginManager::class); |
| 25 | + $this->assertInstanceOf(SmtpPluginManager::class, $plugins); |
| 26 | + |
| 27 | + if (method_exists($plugins, 'configure')) { |
| 28 | + // zend-servicemanager v3 |
| 29 | + $this->assertAttributeSame($container, 'creationContext', $plugins); |
| 30 | + } else { |
| 31 | + // zend-servicemanager v2 |
| 32 | + $this->assertSame($container, $plugins->getServiceLocator()); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @depends testFactoryReturnsPluginManager |
| 38 | + */ |
| 39 | + public function testFactoryConfiguresPluginManagerUnderContainerInterop() |
| 40 | + { |
| 41 | + $container = $this->prophesize(ContainerInterface::class)->reveal(); |
| 42 | + $smtp = $this->prophesize(Smtp::class)->reveal(); |
| 43 | + |
| 44 | + $factory = new SmtpPluginManagerFactory(); |
| 45 | + $plugins = $factory($container, SmtpPluginManager::class, [ |
| 46 | + 'services' => [ |
| 47 | + 'test' => $smtp, |
| 48 | + ], |
| 49 | + ]); |
| 50 | + $this->assertSame($smtp, $plugins->get('test')); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @depends testFactoryReturnsPluginManager |
| 55 | + */ |
| 56 | + public function testFactoryConfiguresPluginManagerUnderServiceManagerV2() |
| 57 | + { |
| 58 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 59 | + $container->willImplement(ContainerInterface::class); |
| 60 | + |
| 61 | + $smtp = $this->prophesize(Smtp::class)->reveal(); |
| 62 | + |
| 63 | + $factory = new SmtpPluginManagerFactory(); |
| 64 | + $factory->setCreationOptions([ |
| 65 | + 'services' => [ |
| 66 | + 'test' => $smtp, |
| 67 | + ], |
| 68 | + ]); |
| 69 | + |
| 70 | + $plugins = $factory->createService($container->reveal()); |
| 71 | + $this->assertSame($smtp, $plugins->get('test')); |
| 72 | + } |
| 73 | +} |
0 commit comments