Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 81db40e

Browse files
committed
Update IdentityFactoryTest to vary behavior based on zend-servicemanager version
Which container is passed to the factory is determined based on which zend-servicemanager version we are in. In v3, the parent/peering container is provided to the factory; in v2, the plugin manager is, and we must pull the parent from it.
1 parent fcdeea8 commit 81db40e

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

test/Helper/Service/IdentityFactoryTest.php

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,69 @@
1212
use Zend\Authentication\AuthenticationServiceInterface;
1313
use Zend\ServiceManager\ServiceManager;
1414
use Zend\View\Helper\Identity;
15+
use Zend\View\HelperPluginManager;
1516
use Zend\View\Helper\Service\IdentityFactory;
1617

1718
class IdentityFactoryTest extends TestCase
1819
{
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+
1934
public function testFactoryReturnsEmptyIdentityIfNoAuthenticationServicePresent()
2035
{
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();
2640

2741
$factory = new IdentityFactory();
28-
$plugin = $factory($container->reveal(), Identity::class);
42+
43+
$plugin = $factory($this->getContainerForFactory(), Identity::class);
2944

3045
$this->assertInstanceOf(Identity::class, $plugin);
3146
$this->assertNull($plugin->getAuthenticationService());
3247
}
3348

3449
public function testFactoryReturnsIdentityWithConfiguredAuthenticationServiceWhenPresent()
3550
{
36-
$container = $this->prophesize(ServiceManager::class);
3751
$authentication = $this->prophesize(AuthenticationService::class);
3852

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();
4357

4458
$factory = new IdentityFactory();
45-
$plugin = $factory($container->reveal(), Identity::class);
59+
60+
$plugin = $factory($this->getContainerForFactory(), Identity::class);
4661

4762
$this->assertInstanceOf(Identity::class, $plugin);
4863
$this->assertSame($authentication->reveal(), $plugin->getAuthenticationService());
4964
}
5065

5166
public function testFactoryReturnsIdentityWithConfiguredAuthenticationServiceInterfaceWhenPresent()
5267
{
53-
$container = $this->prophesize(ServiceManager::class);
5468
$authentication = $this->prophesize(AuthenticationServiceInterface::class);
5569

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']);
6074

6175
$factory = new IdentityFactory();
62-
$plugin = $factory($container->reveal(), Identity::class);
76+
77+
$plugin = $factory($this->getContainerForFactory(), Identity::class);
6378

6479
$this->assertInstanceOf(Identity::class, $plugin);
6580
$this->assertSame($authentication->reveal(), $plugin->getAuthenticationService());

0 commit comments

Comments
 (0)