ChainServiceFactoryTest.php 1.58 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();
26
        $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []);
27
28
29
        $this->ldapStorage    = $this->getMock('UnicaenAuth\Authentication\Storage\Ldap', $this->events);
        $this->dbStorage      = $this->getMock('UnicaenAuth\Authentication\Storage\Db', $this->events);
    }
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->createService($this->serviceLocator);
38

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

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