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

namespace UnicaenAuthTest\Provider\Role;

/**
 * Description of DbServiceFactoryTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class DbServiceFactoryTest extends BaseServiceFactoryTest
{
12
13
    protected $factoryClass = 'UnicaenAuth\Provider\Role\DbRoleServiceFactory';
    protected $serviceClass = 'UnicaenAuth\Provider\Role\DbRole';
14
15
16
17
18
19
20
            
    public function provideInvalidOptions()
    {
        return array(
            'a' => array(array()),
            'b' => array(array('role_providers')),
            'c' => array(array('role_providers' => array())),
21
22
23
            'd' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\DbRole' => array()))),
            'e' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\DbRole' => array('role_entity_class' => null)))),
            'f' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\DbRole' => array('role_entity_class' => 'A', 'object_manager' => null)))),
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
        );
    }
    
    /**
     * @dataProvider provideInvalidOptions
     * @expectedException \BjyAuthorize\Exception\InvalidArgumentException
     */
    public function testCannotCreateServiceWithInvalidOptions($options)
    {
        $this->serviceLocator->expects($this->once())
                ->method('get')
                ->with('BjyAuthorize\Config')
                ->will($this->returnValue($options));
        
        $this->factory->createService($this->serviceLocator);
    }
    
    public function testCanCreateService()
    {
        $options = array(
            'role_providers' => array(
45
                'UnicaenAuth\Provider\Role\DbRole' => array(
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
                    'role_entity_class' => 'Entity', 
                    'object_manager'    => 'orm_default',
                )
            )
        );
        
        $objectManager = $this->getMockForAbstractClass('Doctrine\Common\Persistence\ObjectManager', array('getRepository'));
        $objectManager->expects($this->once())
                ->method('getRepository')
                ->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository', array())));
        
        $map = array(
            array('BjyAuthorize\Config', $options),
            array('orm_default',         $objectManager),
        );
        $this->serviceLocator->expects($this->exactly(2))
                ->method('get')
                ->will($this->returnValueMap($map));
        
        $service = $this->factory->createService($this->serviceLocator);
        
67
        $this->assertInstanceOf('UnicaenAuth\Provider\Role\DbRole', $service);
68
69
    }
}