BaseServiceFactoryTest.php 1.71 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuthTest\Provider\Identity;

5
use PHPUnit\Framework\TestCase;
6
7
8
9
10
11

/**
 * Description of BaseServiceFactoryTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
12
abstract class BaseServiceFactoryTest extends TestCase
13
14
15
16
17
18
{
    protected $serviceLocator;
    protected $userService;
    protected $factory;
    protected $factoryClass;
    protected $serviceClass;
19

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 $this->factoryClass();
27
28
29
        $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', []);
        $this->authService    = $this->getMock('Zend\Authentication\AuthenticationService', []);
        $this->userService    = $this->getMock('ZfcUser\Service\User', ['getAuthService']);
30
    }
31

32
33
34
35
36
    public function testCanCreateService()
    {
        $this->userService->expects($this->once())
                ->method('getAuthService')
                ->will($this->returnValue($this->authService));
37
38
39
40
41

        $map = [
            ['zfcuser_user_service', $this->userService],
            ['BjyAuthorize\Config',  ['default_role' => 'default', 'authenticated_role' => 'auth']],
        ];
42
43
44
        $this->serviceLocator->expects($this->any())
                ->method('get')
                ->will($this->returnValueMap($map));
45

46
        $service = $this->factory->createService($this->serviceLocator);
47

48
49
50
51
52
        $this->assertInstanceOf($this->serviceClass, $service);
        $this->assertEquals('default', $service->getDefaultRole());
        $this->assertEquals('auth', $service->getAuthenticatedRole());
    }
}