BaseServiceFactoryTest.php 1.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

namespace UnicaenAuthTest\Provider\Identity;

use PHPUnit_Framework_TestCase;

/**
 * Description of BaseServiceFactoryTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
abstract class BaseServiceFactoryTest extends PHPUnit_Framework_TestCase
{
    protected $serviceLocator;
    protected $userService;
    protected $factory;
    protected $factoryClass;
    protected $serviceClass;
            
    /**
     * 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();
        $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface', array());
        $this->authService    = $this->getMock('Zend\Authentication\AuthenticationService', array());
        $this->userService    = $this->getMock('ZfcUser\Service\User', array('getAuthService'));
    }
    
    public function testCanCreateService()
    {
        $this->userService->expects($this->once())
                ->method('getAuthService')
                ->will($this->returnValue($this->authService));
        
        $map = array(
            array('zfcuser_user_service', $this->userService),
            array('BjyAuthorize\Config',  array('default_role' => 'default', 'authenticated_role' => 'auth')),
        );
        $this->serviceLocator->expects($this->any())
                ->method('get')
                ->will($this->returnValueMap($map));
        
        $service = $this->factory->createService($this->serviceLocator);
        
        $this->assertInstanceOf($this->serviceClass, $service);
        $this->assertEquals('default', $service->getDefaultRole());
        $this->assertEquals('auth', $service->getAuthenticatedRole());
    }
}