DbTest.php 1.48 KB
Newer Older
1
2
3
4
5
<?php

namespace UnicaenAuthTest\Provider\Role;

use PHPUnit_Framework_TestCase;
6
use UnicaenAuth\Provider\Role\DbRole;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use BjyAuthorize\Provider\Role\ObjectRepositoryProvider;

/**
 * Description of DbTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class DbTest extends PHPUnit_Framework_TestCase
{
    protected $provider;
    protected $objectRepository;
    
    protected function setUp()
    {
        $this->objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository', array());
22
        $this->provider         = new DbRole($this->objectRepository);
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
53
54
55
56
57
58
59
    }
    
    public function testGettingRolesReturnsParentClassRoles()
    {
        ObjectRepositoryProvider::$throwException = false;
        $this->assertEquals(array('Role 1', 'Role 2'), $this->provider->getRoles());
    }
    
    public function testException()
    {
        ObjectRepositoryProvider::$throwException = true;
        $this->assertEquals(array(), $this->provider->getRoles());
    }
}

namespace BjyAuthorize\Provider\Role;

use Doctrine\Common\Persistence\ObjectRepository;

class ObjectRepositoryProvider implements ProviderInterface
{
    public static $throwException = false;
    
    public function __construct(ObjectRepository $objectRepository)
    {
    }
    
    public function getRoles()
    {
        if (self::$throwException) {
            throw new \PDOException("No db connection!");
        }
        else {
            return array('Role 1', 'Role 2');
        }
    }
}