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
|
|
|
|