This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Tests\Entity; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\Entity\Group; |
||
6 | use Kunstmaan\AdminBundle\Entity\Role; |
||
7 | use PHPUnit\Framework\TestCase; |
||
8 | use Symfony\Component\Validator\Validation; |
||
9 | |||
10 | /** |
||
11 | * Generated by PHPUnit_SkeletonGenerator on 2012-08-28 at 17:50:57. |
||
12 | */ |
||
13 | class GroupTest extends TestCase |
||
14 | { |
||
15 | /** |
||
16 | * @var Group |
||
17 | */ |
||
18 | protected $object; |
||
19 | |||
20 | /** |
||
21 | * Sets up the fixture, for example, opens a network connection. |
||
22 | * This method is called before a test is executed. |
||
23 | */ |
||
24 | protected function setUp(): void |
||
25 | { |
||
26 | $this->object = new Group('group'); |
||
27 | } |
||
28 | |||
29 | public function testGetId() |
||
30 | { |
||
31 | $this->assertEquals(null, $this->object->getId()); |
||
32 | } |
||
33 | |||
34 | public function test__toString() |
||
35 | { |
||
36 | $this->assertEquals('group', $this->object->__toString()); |
||
37 | } |
||
38 | |||
39 | public function testGetRoles() |
||
40 | { |
||
41 | /* @var $role Role */ |
||
42 | $role = $this->getRole(); |
||
43 | $this->object->addRole($role); |
||
44 | |||
45 | $this->assertEquals(array('role1'), $this->object->getRoles()); |
||
46 | } |
||
47 | |||
48 | public function testGetRolesCollection() |
||
49 | { |
||
50 | /* @var $role Role */ |
||
51 | $role = $this->getRole(); |
||
52 | $this->object->addRole($role); |
||
53 | |||
54 | $collection = new \Doctrine\Common\Collections\ArrayCollection(); |
||
55 | $collection->add($role); |
||
56 | |||
57 | $this->assertEquals($collection, $this->object->getRolesCollection()); |
||
58 | } |
||
59 | |||
60 | public function testGetRole() |
||
61 | { |
||
62 | /* @var $role Role */ |
||
63 | $role = $this->getRole(); |
||
64 | $this->object->addRole($role); |
||
65 | |||
66 | $result = $this->object->getRole('role1'); |
||
67 | $this->assertEquals($role, $result); |
||
68 | |||
69 | $result = $this->object->getRole('role2'); |
||
70 | $this->assertEquals(null, $result); |
||
71 | } |
||
72 | |||
73 | public function testHasRole() |
||
74 | { |
||
75 | /* @var $role Role */ |
||
76 | $role = $this->getRole(); |
||
77 | $this->object->addRole($role); |
||
78 | |||
79 | $this->assertTrue($this->object->hasRole('role1')); |
||
80 | $this->assertFalse($this->object->hasRole('role2')); |
||
81 | } |
||
82 | |||
83 | View Code Duplication | public function testRemoveRole() |
|
84 | { |
||
85 | /* @var $role Role */ |
||
86 | $role = $this->getRole(); |
||
87 | $this->object->addRole($role); |
||
88 | $this->assertTrue($this->object->hasRole('role1')); |
||
89 | |||
90 | $this->object->removeRole('role1'); |
||
91 | $this->assertFalse($this->object->hasRole('role1')); |
||
92 | } |
||
93 | |||
94 | public function testAddRoleWithInvalidParameter() |
||
95 | { |
||
96 | $this->expectException(\InvalidArgumentException::class); |
||
97 | /* @var $role Role */ |
||
98 | $role = new \StdClass(); |
||
99 | $this->object->addRole($role); |
||
100 | } |
||
101 | |||
102 | public function testSetRoles() |
||
103 | { |
||
104 | $role1 = $this->getRole('role1'); |
||
105 | $role2 = $this->getRole('role2'); |
||
106 | $role3 = $this->getRole('role3'); |
||
107 | $roles = array($role1, $role2, $role3); |
||
108 | $this->object->setRoles($roles); |
||
109 | |||
110 | $this->assertCount(3, $this->object->getRoles()); |
||
111 | } |
||
112 | |||
113 | public function testSetRolesCollection() |
||
114 | { |
||
115 | $role1 = $this->getRole('role1'); |
||
116 | $role2 = $this->getRole('role2'); |
||
117 | $role3 = $this->getRole('role3'); |
||
118 | |||
119 | $roles = new \Doctrine\Common\Collections\ArrayCollection(); |
||
120 | $roles->add($role1); |
||
121 | $roles->add($role2); |
||
122 | $roles->add($role3); |
||
123 | |||
124 | $this->object->setRolesCollection($roles); |
||
125 | $this->assertEquals(3, $this->object->getRolesCollection()->count()); |
||
126 | } |
||
127 | |||
128 | public function testConstructorAndGetSetName() |
||
129 | { |
||
130 | $object = new Group('testgroup'); |
||
131 | $this->assertEquals('testgroup', $object->getName()); |
||
132 | |||
133 | $object->setName('group2'); |
||
134 | $this->assertEquals('group2', $object->getName()); |
||
135 | } |
||
136 | |||
137 | View Code Duplication | public function testValidateGroupWithoutRole() |
|
138 | { |
||
139 | $group = new Group('test'); |
||
140 | |||
141 | $validator = Validation::createValidatorBuilder() |
||
142 | ->enableAnnotationMapping() |
||
143 | ->getValidator(); |
||
144 | |||
145 | $violations = $validator->validate($group); |
||
146 | |||
147 | $this->assertCount(1, $violations); |
||
148 | } |
||
149 | |||
150 | View Code Duplication | public function testValidateGroupWithRole() |
|
151 | { |
||
152 | $group = new Group('test'); |
||
153 | $group->addRole(new Role('role')); |
||
154 | |||
155 | $validator = Validation::createValidatorBuilder() |
||
156 | ->enableAnnotationMapping() |
||
157 | ->getValidator(); |
||
158 | |||
159 | $violations = $validator->validate($group); |
||
160 | |||
161 | $this->assertCount(0, $violations); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @param string $name |
||
166 | * |
||
167 | * @return \Kunstmaan\AdminBundle\Entity\Role |
||
0 ignored issues
–
show
|
|||
168 | */ |
||
169 | protected function getRole($name = 'role1') |
||
170 | { |
||
171 | $role = $this->getMockBuilder('Kunstmaan\AdminBundle\Entity\Role') |
||
172 | ->disableOriginalConstructor() |
||
173 | ->getMock(); |
||
174 | $role->expects($this->any()) |
||
175 | ->method('getRole') |
||
176 | ->will($this->returnValue($name)); |
||
177 | |||
178 | return $role; |
||
179 | } |
||
180 | } |
||
181 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.