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

Commit c19356a

Browse files
gszyweierophinney
authored andcommitted
IdentityFactoryTest
1 parent 0e4979f commit c19356a

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-view for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-view/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace ZendTest\View\Helper\Service;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Zend\Authentication\AuthenticationService;
12+
use Zend\Authentication\AuthenticationServiceInterface;
13+
use Zend\ServiceManager\ServiceManager;
14+
use Zend\View\Helper\Identity;
15+
use Zend\View\Helper\Service\IdentityFactory;
16+
17+
class IdentityFactoryTest extends TestCase
18+
{
19+
public function testFactoryReturnsEmptyIdentityIfNoAuthenticationServicePresent()
20+
{
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();
26+
27+
$factory = new IdentityFactory();
28+
$plugin = $factory($container->reveal(), Identity::class);
29+
30+
$this->assertInstanceOf(Identity::class, $plugin);
31+
$this->assertNull($plugin->getAuthenticationService());
32+
}
33+
34+
public function testFactoryReturnsIdentityWithConfiguredAuthenticationServiceWhenPresent()
35+
{
36+
$container = $this->prophesize(ServiceManager::class);
37+
$authentication = $this->prophesize(AuthenticationService::class);
38+
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();
43+
44+
$factory = new IdentityFactory();
45+
$plugin = $factory($container->reveal(), Identity::class);
46+
47+
$this->assertInstanceOf(Identity::class, $plugin);
48+
$this->assertSame($authentication->reveal(), $plugin->getAuthenticationService());
49+
}
50+
51+
public function testFactoryReturnsIdentityWithConfiguredAuthenticationServiceInterfaceWhenPresent()
52+
{
53+
$container = $this->prophesize(ServiceManager::class);
54+
$authentication = $this->prophesize(AuthenticationServiceInterface::class);
55+
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']);
60+
61+
$factory = new IdentityFactory();
62+
$plugin = $factory($container->reveal(), Identity::class);
63+
64+
$this->assertInstanceOf(Identity::class, $plugin);
65+
$this->assertSame($authentication->reveal(), $plugin->getAuthenticationService());
66+
}
67+
}

0 commit comments

Comments
 (0)