GroupTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 65
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testConstructor() 0 27 1
B testSetters() 0 28 1
1
<?php
2
3
/*
4
 * (c) Jim Martens <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace TwoMartens\Bundle\CoreBundle\Tests\Model;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use TwoMartens\Bundle\CoreBundle\Model\OptionCategory;
14
use TwoMartens\Bundle\CoreBundle\Model\Group;
15
16
/**
17
 * Tests the Group class.
18
 *
19
 * @author    Jim Martens <[email protected]>
20
 * @copyright 2013-2015 Jim Martens
21
 */
22
class GroupTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * Tests the constructor.
26
     */
27
    public function testConstructor()
28
    {
29
        $frontendUserCategory = new OptionCategory('twomartens.core.group.category.frontendUser');
30
        $frontendModCategory = new OptionCategory('twomartens.core.group.category.frontendMod');
31
        $acpCategory = new OptionCategory('twomartens.core.group.category.acp');
32
        $group = new Group(
33
            0,
34
            'ADMIN',
35
            'twomartens.core.group.admin',
36
            true,
37
            false,
38
            [],
39
            $frontendUserCategory,
40
            $frontendModCategory,
41
            $acpCategory
42
        );
43
44
        $this->assertEquals(0, $group->getId());
45
        $this->assertEquals('ADMIN', $group->getRoleName());
46
        $this->assertEquals('twomartens.core.group.admin', $group->getPublicName());
47
        $this->assertTrue($group->isEssential());
48
        $this->assertFalse($group->canBeEmpty());
49
        $this->assertEquals($frontendUserCategory, $group->getFrontendUserCategory());
50
        $this->assertEquals($frontendModCategory, $group->getFrontendModCategory());
51
        $this->assertEquals($acpCategory, $group->getACPCategory());
52
        $this->assertTrue($group->getUsers()->isEmpty());
53
    }
54
55
    /**
56
     * Tests the setters.
57
     */
58
    public function testSetters()
59
    {
60
        $frontendUserCategory = new OptionCategory('twomartens.core.group.category.frontendUser');
61
        $frontendModCategory = new OptionCategory('twomartens.core.group.category.frontendMod');
62
        $acpCategory = new OptionCategory('twomartens.core.group.category.acp');
63
        $group = new Group(
64
            0,
65
            'ADMIN',
66
            'twomartens.core.group.admin',
67
            true,
68
            false,
69
            [],
70
            $frontendUserCategory,
71
            $frontendModCategory,
72
            $acpCategory
73
        );
74
        // test public name
75
        $group->setPublicName('Administrators');
76
        $this->assertEquals('Administrators', $group->getPublicName());
77
        // test role name
78
        $group->setRoleName('SUPER_ADMIN');
79
        $this->assertEquals('SUPER_ADMIN', $group->getRoleName());
80
        // test users
81
        $user = $this->getMock('\TwoMartens\Bundle\CoreBundle\Model\User');
82
        $users = new ArrayCollection([$user]);
83
        $group->setUsers($users);
84
        $this->assertEquals($users, $group->getUsers());
85
    }
86
}
87