ChainServiceFactoryTest.php 1.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

namespace UnicaenAuthTest\Provider\Identity;

use PHPUnit_Framework_TestCase;
use UnicaenAuth\Provider\Identity\ChainServiceFactory;

/**
 * Description of ChainServiceFactoryTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class ChainServiceFactoryTest extends PHPUnit_Framework_TestCase
{
    protected $serviceLocator;
    protected $eventManager;
    protected $factory;
18
19
    protected $events = ['getIdentityRoles'];

20
21
22
23
24
25
26
    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
        $this->factory        = new ChainServiceFactory();
27
28
29
        $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []);
        $this->ldapProvider   = $this->getMock('UnicaenAuth\Provider\Identity\Ldap', $this->events, [], '', false);
        $this->dbProvider     = $this->getMock('UnicaenAuth\Provider\Identity\Db', $this->events, [], '', false);
30
    }
31

32
33
34
35
36
    public function testCanCreateService()
    {
        $this->serviceLocator->expects($this->exactly(2))
                ->method('get')
                ->will($this->onConsecutiveCalls($this->dbProvider, $this->ldapProvider));
37

38
        $service = $this->factory->createService($this->serviceLocator);
39

40
        $this->assertInstanceOf('UnicaenAuth\Provider\Identity\Chain', $service);
41

42
43
44
45
46
47
        foreach ($this->events as $event) {
            $listeners = $service->getEventManager()->getListeners($event); /* @var $listeners \Zend\Stdlib\SplPriorityQueue */
            $this->assertCount(2, $listeners);
        }
    }
}