TestGroupTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 86
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testValid() 0 17 1
A testCreatedAtIsImmutable() 0 7 1
A testMinimallySatisfiesGroupInterface() 0 15 1
A testAddRemoveTests() 0 17 1
A createTest() 0 9 1
1
<?php
2
3
namespace Overwatch\TestBundle\Tests\Entity;
4
5
use Overwatch\TestBundle\Entity\Test;
6
use Overwatch\TestBundle\Entity\TestGroup;
7
8
/**
9
 * TestGroupTest
10
 * A unit test for the TestGroup Entity.
11
 */
12
class TestGroupTest extends \PHPUnit_Framework_TestCase
13
{
14
    private $group;
15
    
16
    const GROUP_NAME = 'TestGroup! Testing!';
17
    
18
    public function setUp()
19
    {
20
        $this->group = new TestGroup;
21
        $this->group
22
            ->setName(self::GROUP_NAME)
23
            ->setCreatedAt()
24
            ->setUpdatedAt()
25
        ;
26
    }
27
    
28
    public function testValid()
29
    {
30
        $this->assertEquals(self::GROUP_NAME, $this->group->getName());
31
        $this->assertInstanceOf('\DateTime', $this->group->getCreatedAt());
32
        $this->assertInstanceOf('\DateTime', $this->group->getUpdatedAt());
33
        $this->assertJsonStringEqualsJsonString(
34
            json_encode([
35
                'id'        => null,
36
                'name'      => self::GROUP_NAME,
37
                'tests'     => [],
38
                'users'     => [],
39
                'createdAt' => $this->group->getCreatedAt()->getTimestamp(),
40
                'updatedAt' => $this->group->getUpdatedAt()->getTimestamp()
41
            ]),
42
            json_encode($this->group)
43
        );
44
    }
45
    
46
    public function testCreatedAtIsImmutable()
47
    {
48
        $expected = $this->group->getCreatedAt();
49
        
50
        $this->group->setCreatedAt();
51
        $this->assertEquals($expected, $this->group->getCreatedAt());
52
    }
53
    
54
    public function testMinimallySatisfiesGroupInterface()
55
    {
56
        $this->assertInstanceOf('\FOS\UserBundle\Model\GroupInterface', $this->group);
57
        $this->assertEquals([], $this->group->getRoles());
58
        $this->assertFalse($this->group->hasRole('ANYTHING'));
59
        
60
        $this->assertEquals($this->group, $this->group->addRole('SOMETHING'));
61
        $this->assertEquals([], $this->group->getRoles());
62
        
63
        $this->assertEquals($this->group, $this->group->removeRole('WHATEVER'));
64
        $this->assertEquals([], $this->group->getRoles());
65
        
66
        $this->assertEquals($this->group, $this->group->setRoles(['A_B_C']));
67
        $this->assertEquals([], $this->group->getRoles());
68
    }
69
    
70
    public function testAddRemoveTests()
71
    {
72
        $test1 = $this->createTest('Test 1');
73
        $test2 = $this->createTest('TestTwo');
74
        
75
        $this->group->addTest($test1);
76
        $this->assertCount(1, $this->group->getTests());
77
        $this->assertContains($test1, $this->group->getTests());
78
        
79
        $this->group->addTest($test2);
80
        $this->assertCount(2, $this->group->getTests());
81
        $this->assertContains($test2, $this->group->getTests());
82
        
83
        $this->group->removeTest($test1);
84
        $this->assertCount(1, $this->group->getTests());
85
        $this->assertNotContains($test1, $this->group->getTests());
86
    }
87
    
88
    private function createTest($name)
89
    {
90
        $test = new Test;
91
        $test->setName($name)
92
            ->setActual('8.8.8.8')
93
            ->setExpectation('toPing');
94
        
95
        return $test;
96
    }
97
}
98