|
12 | 12 | use Zend\Authentication\AuthenticationServiceInterface; |
13 | 13 | use Zend\ServiceManager\ServiceManager; |
14 | 14 | use Zend\View\Helper\Identity; |
| 15 | +use Zend\View\HelperPluginManager; |
15 | 16 | use Zend\View\Helper\Service\IdentityFactory; |
16 | 17 |
|
17 | 18 | class IdentityFactoryTest extends TestCase |
18 | 19 | { |
| 20 | + public function setUp() |
| 21 | + { |
| 22 | + $this->services = $this->prophesize(ServiceManager::class); |
| 23 | + $this->helpers = new HelperPluginManager($this->services->reveal()); |
| 24 | + } |
| 25 | + |
| 26 | + public function getContainerForFactory() |
| 27 | + { |
| 28 | + if (method_exists($this->helpers, 'configure')) { |
| 29 | + return $this->services->reveal(); |
| 30 | + } |
| 31 | + return $this->helpers; |
| 32 | + } |
| 33 | + |
19 | 34 | public function testFactoryReturnsEmptyIdentityIfNoAuthenticationServicePresent() |
20 | 35 | { |
21 | | - $container = $this->prophesize(ServiceManager::class); |
22 | | - $container->has(AuthenticationService::class)->willReturn(false); |
23 | | - $container->get(AuthenticationService::class)->shouldNotBeCalled(); |
24 | | - $container->has(AuthenticationServiceInterface::class)->willReturn(false); |
25 | | - $container->get(AuthenticationServiceInterface::class)->shouldNotBeCalled(); |
| 36 | + $this->services->has(AuthenticationService::class)->willReturn(false); |
| 37 | + $this->services->get(AuthenticationService::class)->shouldNotBeCalled(); |
| 38 | + $this->services->has(AuthenticationServiceInterface::class)->willReturn(false); |
| 39 | + $this->services->get(AuthenticationServiceInterface::class)->shouldNotBeCalled(); |
26 | 40 |
|
27 | 41 | $factory = new IdentityFactory(); |
28 | | - $plugin = $factory($container->reveal(), Identity::class); |
| 42 | + |
| 43 | + $plugin = $factory($this->getContainerForFactory(), Identity::class); |
29 | 44 |
|
30 | 45 | $this->assertInstanceOf(Identity::class, $plugin); |
31 | 46 | $this->assertNull($plugin->getAuthenticationService()); |
32 | 47 | } |
33 | 48 |
|
34 | 49 | public function testFactoryReturnsIdentityWithConfiguredAuthenticationServiceWhenPresent() |
35 | 50 | { |
36 | | - $container = $this->prophesize(ServiceManager::class); |
37 | 51 | $authentication = $this->prophesize(AuthenticationService::class); |
38 | 52 |
|
39 | | - $container->has(AuthenticationService::class)->willReturn(true); |
40 | | - $container->get(AuthenticationService::class)->will([$authentication, 'reveal']); |
41 | | - $container->has(AuthenticationServiceInterface::class)->willReturn(false); |
42 | | - $container->get(AuthenticationServiceInterface::class)->shouldNotBeCalled(); |
| 53 | + $this->services->has(AuthenticationService::class)->willReturn(true); |
| 54 | + $this->services->get(AuthenticationService::class)->will([$authentication, 'reveal']); |
| 55 | + $this->services->has(AuthenticationServiceInterface::class)->willReturn(false); |
| 56 | + $this->services->get(AuthenticationServiceInterface::class)->shouldNotBeCalled(); |
43 | 57 |
|
44 | 58 | $factory = new IdentityFactory(); |
45 | | - $plugin = $factory($container->reveal(), Identity::class); |
| 59 | + |
| 60 | + $plugin = $factory($this->getContainerForFactory(), Identity::class); |
46 | 61 |
|
47 | 62 | $this->assertInstanceOf(Identity::class, $plugin); |
48 | 63 | $this->assertSame($authentication->reveal(), $plugin->getAuthenticationService()); |
49 | 64 | } |
50 | 65 |
|
51 | 66 | public function testFactoryReturnsIdentityWithConfiguredAuthenticationServiceInterfaceWhenPresent() |
52 | 67 | { |
53 | | - $container = $this->prophesize(ServiceManager::class); |
54 | 68 | $authentication = $this->prophesize(AuthenticationServiceInterface::class); |
55 | 69 |
|
56 | | - $container->has(AuthenticationService::class)->willReturn(false); |
57 | | - $container->get(AuthenticationService::class)->shouldNotBeCalled(); |
58 | | - $container->has(AuthenticationServiceInterface::class)->willReturn(true); |
59 | | - $container->get(AuthenticationServiceInterface::class)->will([$authentication, 'reveal']); |
| 70 | + $this->services->has(AuthenticationService::class)->willReturn(false); |
| 71 | + $this->services->get(AuthenticationService::class)->shouldNotBeCalled(); |
| 72 | + $this->services->has(AuthenticationServiceInterface::class)->willReturn(true); |
| 73 | + $this->services->get(AuthenticationServiceInterface::class)->will([$authentication, 'reveal']); |
60 | 74 |
|
61 | 75 | $factory = new IdentityFactory(); |
62 | | - $plugin = $factory($container->reveal(), Identity::class); |
| 76 | + |
| 77 | + $plugin = $factory($this->getContainerForFactory(), Identity::class); |
63 | 78 |
|
64 | 79 | $this->assertInstanceOf(Identity::class, $plugin); |
65 | 80 | $this->assertSame($authentication->reveal(), $plugin->getAuthenticationService()); |
|
0 commit comments