|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @link http://github.com/zendframework/zend-validator 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\Validator; |
| 9 | + |
| 10 | +use Interop\Container\ContainerInterface; |
| 11 | +use PHPUnit_Framework_TestCase as TestCase; |
| 12 | +use Zend\Validator\ValidatorInterface; |
| 13 | +use Zend\Validator\ValidatorPluginManager; |
| 14 | +use Zend\Validator\ValidatorPluginManagerFactory; |
| 15 | +use Zend\ServiceManager\ServiceLocatorInterface; |
| 16 | + |
| 17 | +class ValidatorPluginManagerFactoryTest extends TestCase |
| 18 | +{ |
| 19 | + public function testFactoryReturnsPluginManager() |
| 20 | + { |
| 21 | + $container = $this->prophesize(ContainerInterface::class)->reveal(); |
| 22 | + $factory = new ValidatorPluginManagerFactory(); |
| 23 | + |
| 24 | + $validators = $factory($container, ValidatorPluginManagerFactory::class); |
| 25 | + $this->assertInstanceOf(ValidatorPluginManager::class, $validators); |
| 26 | + |
| 27 | + if (method_exists($validators, 'configure')) { |
| 28 | + // zend-servicemanager v3 |
| 29 | + $this->assertAttributeSame($container, 'creationContext', $validators); |
| 30 | + } else { |
| 31 | + // zend-servicemanager v2 |
| 32 | + $this->assertSame($container, $validators->getServiceLocator()); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @depends testFactoryReturnsPluginManager |
| 38 | + */ |
| 39 | + public function testFactoryConfiguresPluginManagerUnderContainerInterop() |
| 40 | + { |
| 41 | + $container = $this->prophesize(ContainerInterface::class)->reveal(); |
| 42 | + $validator = $this->prophesize(ValidatorInterface::class)->reveal(); |
| 43 | + |
| 44 | + $factory = new ValidatorPluginManagerFactory(); |
| 45 | + $validators = $factory($container, ValidatorPluginManagerFactory::class, [ |
| 46 | + 'services' => [ |
| 47 | + 'test' => $validator, |
| 48 | + ], |
| 49 | + ]); |
| 50 | + $this->assertSame($validator, $validators->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 | + $validator = $this->prophesize(ValidatorInterface::class)->reveal(); |
| 62 | + |
| 63 | + $factory = new ValidatorPluginManagerFactory(); |
| 64 | + $factory->setCreationOptions([ |
| 65 | + 'services' => [ |
| 66 | + 'test' => $validator, |
| 67 | + ], |
| 68 | + ]); |
| 69 | + |
| 70 | + $validators = $factory->createService($container->reveal()); |
| 71 | + $this->assertSame($validator, $validators->get('test')); |
| 72 | + } |
| 73 | +} |
0 commit comments