|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Zend Framework (http://framework.zend.com/) |
| 4 | + * |
| 5 | + * @link http://github.com/zendframework/zend-stdlib for the canonical source repository |
| 6 | + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) |
| 7 | + * @license http://framework.zend.com/license/new-bsd New BSD License |
| 8 | + */ |
| 9 | + |
| 10 | +namespace ZendTest\Stdlib\Hydrator; |
| 11 | + |
| 12 | +use PHPUnit_Framework_TestCase as TestCase; |
| 13 | +use ReflectionProperty; |
| 14 | +use Zend\Hydrator\HydratorPluginManager as BasePluginManager; |
| 15 | +use Zend\Stdlib\Hydrator\HydratorInterface; |
| 16 | +use Zend\Stdlib\Hydrator\HydratorPluginManager; |
| 17 | + |
| 18 | +class HydratorPluginManagerTest extends TestCase |
| 19 | +{ |
| 20 | + public function setUp() |
| 21 | + { |
| 22 | + $this->hydrators = new HydratorPluginManager(); |
| 23 | + } |
| 24 | + |
| 25 | + public function testExtendsZendHydratorPluginManager() |
| 26 | + { |
| 27 | + $this->assertInstanceOf(BasePluginManager::class, $this->hydrators); |
| 28 | + } |
| 29 | + |
| 30 | + public function aliases() |
| 31 | + { |
| 32 | + $hydrators = new HydratorPluginManager(); |
| 33 | + $r = new ReflectionProperty($hydrators, 'aliases'); |
| 34 | + $r->setAccessible(true); |
| 35 | + foreach ($r->getValue($hydrators) as $alias => $target) { |
| 36 | + yield $alias => [$alias, $target]; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @dataProvider aliases |
| 42 | + */ |
| 43 | + public function testAllAliasesReturnStdlibEquivalents($alias, $expected) |
| 44 | + { |
| 45 | + $this->assertContains('\\Stdlib\\', $expected, 'Alias target is not a Stdlib class?'); |
| 46 | + |
| 47 | + $hydrator = $this->hydrators->get($alias); |
| 48 | + $this->assertInstanceOf( |
| 49 | + $expected, |
| 50 | + $hydrator, |
| 51 | + sprintf('Alias %s did not retrieve expected %s instance; got %s', $alias, $expected, get_class($hydrator)) |
| 52 | + ); |
| 53 | + $this->assertInstanceOf( |
| 54 | + HydratorInterface::class, |
| 55 | + $hydrator, |
| 56 | + sprintf('Alias %s resolved to %s, which is not a HydratorInterface instance', $alias, get_class($hydrator)) |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + public function invokables() |
| 61 | + { |
| 62 | + $hydrators = new HydratorPluginManager(); |
| 63 | + $r = new ReflectionProperty($hydrators, 'invokableClasses'); |
| 64 | + $r->setAccessible(true); |
| 65 | + foreach ($r->getValue($hydrators) as $name => $target) { |
| 66 | + yield $name => [$name, $target]; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @dataProvider invokables |
| 72 | + */ |
| 73 | + public function testAllInvokablesReturnStdlibInstances($name, $expected) |
| 74 | + { |
| 75 | + $this->assertContains('\\Stdlib\\', $expected, 'Invokable target is not a Stdlib class?'); |
| 76 | + |
| 77 | + $hydrator = $this->hydrators->get($name); |
| 78 | + $this->assertInstanceOf($expected, $hydrator, sprintf( |
| 79 | + 'Invokable %s did not retrieve expected %s instance; got %s', |
| 80 | + $name, |
| 81 | + $expected, |
| 82 | + get_class($hydrator) |
| 83 | + )); |
| 84 | + $this->assertInstanceOf(HydratorInterface::class, $hydrator, sprintf( |
| 85 | + 'Invokable %s resolved to %s, which is not a HydratorInterface instance', |
| 86 | + $name, |
| 87 | + get_class($hydrator) |
| 88 | + )); |
| 89 | + } |
| 90 | + |
| 91 | + public function factories() |
| 92 | + { |
| 93 | + $hydrators = new HydratorPluginManager(); |
| 94 | + $r = new ReflectionProperty($hydrators, 'factories'); |
| 95 | + $r->setAccessible(true); |
| 96 | + foreach ($r->getValue($hydrators) as $name => $factory) { |
| 97 | + yield $name => [$name, $factory]; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * @dataProvider factories |
| 103 | + */ |
| 104 | + public function testAllFactoriesReturnStdlibInstances($name, $factory) |
| 105 | + { |
| 106 | + $hydrator = $this->hydrators->get($name); |
| 107 | + $this->assertInstanceOf(HydratorInterface::class, $hydrator, sprintf( |
| 108 | + 'Factory for %s resolved to %s, which is not a HydratorInterface instance', |
| 109 | + $name, |
| 110 | + get_class($hydrator) |
| 111 | + )); |
| 112 | + } |
| 113 | +} |
0 commit comments