ChainServiceFactoryTest.php 1.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php

namespace UnicaenAuthTest\Authentication\Storage;

use UnicaenAuth\Authentication\Storage\ChainServiceFactory;

/**
 * Description of ChainServiceFactory
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
12
class ChainServiceFactoryTest extends \PHPUnit_Framework_TestCase
13
14
15
16
{
    protected $serviceLocator;
    protected $eventManager;
    protected $factory;
17
18
    protected $events = ['read', 'write', 'clear'];

19
20
21
22
23
24
25
    /**
     * 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();
Bertrand Gauthier's avatar
Bertrand Gauthier committed
26
        $this->serviceLocator = $this->createMock('Laminas\ServiceManager\ServiceLocatorInterface'/*, []*/);
27
28
        $this->ldapStorage    = $this->createMock('UnicaenAuth\Authentication\Storage\Ldap'/*, $this->events*/);
        $this->dbStorage      = $this->createMock('UnicaenAuth\Authentication\Storage\Db'/*, $this->events*/);
29
    }
30

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

37
        $service = $this->factory->__invoke($this->serviceLocator, '');
38

39
        $this->assertInstanceOf('UnicaenAuth\Authentication\Storage\Chain', $service);
40

41
        foreach ($this->events as $event) {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
42
            $listeners = $service->getEventManager()->getListeners($event); /* @var $listeners \Laminas\Stdlib\SplPriorityQueue */
43
44
45
46
            $this->assertCount(2, $listeners);
        }
    }
}