|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Zend Framework (http://framework.zend.com/) |
| 4 | + * |
| 5 | + * @see https://github.com/zendframework/zend-expressive for the canonical source repository |
| 6 | + * @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) |
| 7 | + * @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License |
| 8 | + */ |
| 9 | + |
| 10 | +namespace ZendTest\Expressive\ZendView; |
| 11 | + |
| 12 | +use Interop\Container\ContainerInterface; |
| 13 | +use PHPUnit_Framework_TestCase as TestCase; |
| 14 | +use Zend\Expressive\ZendView\HelperPluginManagerFactory; |
| 15 | +use Zend\ServiceManager\ServiceManager; |
| 16 | +use Zend\View\HelperPluginManager; |
| 17 | +use ZendTest\Expressive\ZendView\TestAsset\TestHelper; |
| 18 | + |
| 19 | +class HelperPluginManagerFactoryTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var ContainerInterface |
| 23 | + */ |
| 24 | + private $container; |
| 25 | + |
| 26 | + public function setUp() |
| 27 | + { |
| 28 | + $this->container = $this->prophesize(ServiceManager::class); |
| 29 | + } |
| 30 | + |
| 31 | + public function testCallingFactoryWithNoConfigReturnsHelperPluginManagerInstance() |
| 32 | + { |
| 33 | + $this->container->has('config')->willReturn(false); |
| 34 | + $factory = new HelperPluginManagerFactory(); |
| 35 | + $manager = $factory($this->container->reveal()); |
| 36 | + $this->assertInstanceOf(HelperPluginManager::class, $manager); |
| 37 | + return $manager; |
| 38 | + } |
| 39 | + |
| 40 | + public function testCallingFactoryWithNoViewHelperConfigReturnsHelperPluginManagerInstance() |
| 41 | + { |
| 42 | + $this->container->has('config')->willReturn(true); |
| 43 | + $this->container->get('config')->willReturn([]); |
| 44 | + $factory = new HelperPluginManagerFactory(); |
| 45 | + $manager = $factory($this->container->reveal()); |
| 46 | + $this->assertInstanceOf(HelperPluginManager::class, $manager); |
| 47 | + return $manager; |
| 48 | + } |
| 49 | + |
| 50 | + public function testCallingFactoryWithConfigAllowsAddingHelpers() |
| 51 | + { |
| 52 | + $this->container->has('config')->willReturn(true); |
| 53 | + $this->container->get('config')->willReturn( |
| 54 | + [ |
| 55 | + 'view_helpers' => [ |
| 56 | + 'invokables' => [ |
| 57 | + 'testHelper' => TestHelper::class, |
| 58 | + ], |
| 59 | + ], |
| 60 | + ] |
| 61 | + ); |
| 62 | + $factory = new HelperPluginManagerFactory(); |
| 63 | + $manager = $factory($this->container->reveal()); |
| 64 | + $this->assertInstanceOf(HelperPluginManager::class, $manager); |
| 65 | + $this->assertTrue($manager->has('testHelper')); |
| 66 | + $this->assertInstanceOf(TestHelper::class, $manager->get('testHelper')); |
| 67 | + return $manager; |
| 68 | + } |
| 69 | +} |
0 commit comments