TestGroupApiControllerTest   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 310
Duplicated Lines 59.35 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 23
lcom 1
cbo 4
dl 184
loc 310
rs 10
c 0
b 0
f 0

23 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateGroup() 0 22 1
A testCreateGroupInsufficentPerms() 0 20 1
A testCreateGroupNoName() 0 16 1
A testGetAllGroups() 16 16 1
A testGetAllGroupsAsUser() 16 16 1
A testGetGroup() 13 13 1
A testGetGroupInsufficentPerms() 7 7 1
A testGetGroupInvalidGroup() 7 7 1
A testUpdateGroup() 23 23 1
A testUpdateGroupInsufficentPerms() 7 7 1
A testUpdateGroupInvalidGroup() 7 7 1
A testDeleteGroup() 8 8 1
A testDeleteGroupPopulatedGroup() 8 8 1
A testDeleteGroupInsufficentPerms() 0 8 1
A testDeleteGroupInvalidGroup() 7 7 1
A testAddUserToGroup() 14 14 1
A testAddUserToGroupInsufficentPerms() 0 13 1
A testAddUserToGroupInvalidGroup() 0 9 1
A testAddUserToGroupInvalidUser() 12 12 1
A testRemoveUserFromGroup() 14 14 1
A testRemoveUserFromGroupInsufficentPerms() 0 13 1
A testRemoveUserFromGroupInvalidGroup() 13 13 1
A testRemoveUserFromGroupInvalidUser() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Overwatch\TestBundle\Tests\Controller;
4
5
use Overwatch\TestBundle\DataFixtures\ORM\TestGroupFixtures;
6
use Overwatch\TestBundle\Entity\TestGroup;
7
use Overwatch\UserBundle\DataFixtures\ORM\UserFixtures;
8
use Overwatch\UserBundle\Tests\Base\DatabaseAwareTestCase;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * TestGroupApiControllerTest
13
 * Functional test of API methods provided by the APIController
14
 */
15
class TestGroupApiControllerTest extends DatabaseAwareTestCase
16
{
17
    public function testCreateGroup()
18
    {
19
        $newGroupName = 'New Group 1';
20
        
21
        $this->logIn('ROLE_SUPER_ADMIN');
22
        $this->makeJsonRequest(
23
            'POST',
24
            '/api/groups',
25
            [
26
                'name' => $newGroupName,
27
            ]
28
        );
29
        
30
        $group = $this->em->getRepository("Overwatch\TestBundle\Entity\TestGroup")->findOneBy([
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
31
            'name' => $newGroupName
32
        ]);
33
        
34
        $this->assertNotNull($group);
35
        
36
        $this->assertJsonResponse($this->client->getResponse());
37
        $this->assertEquals($newGroupName, $this->getResponseContent()->name);
38
    }
39
    
40
    public function testCreateGroupInsufficentPerms()
41
    {
42
        $newGroupName = 'New Group 2';
43
        
44
        $this->logIn('ROLE_ADMIN');
45
        $this->makeJsonRequest(
46
            'POST',
47
            '/api/groups',
48
            [
49
                'name' => $newGroupName,
50
            ]
51
        );
52
        
53
        $group = $this->em->getRepository("Overwatch\TestBundle\Entity\TestGroup")->findOneBy([
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
54
            'name' => $newGroupName
55
        ]);
56
        
57
        $this->assertNull($group);
58
        $this->assertForbidden($this->client->getResponse());
59
    }
60
    
61
    public function testCreateGroupNoName()
62
    {
63
        $this->logIn('ROLE_SUPER_ADMIN');
64
        $this->makeJsonRequest(
65
            'POST',
66
            '/api/groups',
67
            []
68
        );
69
        
70
        $group = $this->em->getRepository("Overwatch\TestBundle\Entity\TestGroup")->findOneBy([
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
71
            'name' => null
72
        ]);
73
        
74
        $this->assertNull($group);
75
        $this->assertEquals(422, $this->client->getResponse()->getStatusCode());
76
    }
77
    
78 View Code Duplication
    public function testGetAllGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $this->logIn('ROLE_SUPER_ADMIN');
81
        $this->client->request('GET', '/api/groups');
82
        
83
        $this->assertJsonResponse($this->client->getResponse());
84
        $this->assertCount(3, $this->getResponseContent());
85
        $this->assertCollectionContainsObject(
86
            $this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-1']->getId()),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
87
            $this->getResponseContent()
88
        );
89
        $this->assertCollectionContainsObject(
90
            $this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-2']->getId()),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
91
            $this->getResponseContent()
92
        );
93
    }
94
    
95 View Code Duplication
    public function testGetAllGroupsAsUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $this->loginAs(
98
            $this->em->find("Overwatch\UserBundle\Entity\User", UserFixtures::$users['user-2']->getId()),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\UserBundle\Entity\User does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
99
            'overwatch'
100
        );
101
        $this->client = $this->makeClient(); //When using loginAs, we must use a new client
102
        $this->client->request('GET', '/api/groups');
103
        
104
        $this->assertJsonResponse($this->client->getResponse());
105
        $this->assertCount(1, $this->getResponseContent());
106
        $this->assertCollectionContainsObject(
107
            $this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-1']->getId()),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
108
            $this->getResponseContent()
109
        );
110
    }
111
    
112 View Code Duplication
    public function testGetGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        $this->logIn('ROLE_SUPER_ADMIN');
115
        $this->client->request('GET', '/api/groups/' . TestGroupFixtures::$groups['group-1']->getId());
116
        
117
        $this->assertJsonResponse($this->client->getResponse());
118
        $this->assertJsonStringEqualsJsonString(
119
            json_encode(
120
                $this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-1']->getId())
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
121
            ),
122
            $this->getResponseContent(true)
123
        );
124
    }
125
    
126 View Code Duplication
    public function testGetGroupInsufficentPerms()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        $this->logIn('ROLE_ADMIN');
129
        $this->client->request('GET', '/api/groups/' . TestGroupFixtures::$groups['group-1']->getId());
130
        
131
        $this->assertForbidden($this->client->getResponse());
132
    }
133
    
134 View Code Duplication
    public function testGetGroupInvalidGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
    {
136
        $this->logIn('ROLE_SUPER_ADMIN');
137
        $this->client->request('GET', '/api/groups/1000');
138
        
139
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
140
    }
141
    
142 View Code Duplication
    public function testUpdateGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
    {
144
        $newName = 'Renamed Group';
145
        
146
        $this->logIn('ROLE_SUPER_ADMIN');
147
        $this->makeJsonRequest(
148
            'PUT',
149
            '/api/groups/' . TestGroupFixtures::$groups['group-2']->getId(),
150
            [
151
                'name' => $newName
152
            ]
153
        );
154
        
155
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-2']->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
156
        
157
        $this->assertEquals($newName, $group->getName());
158
        
159
        $this->assertJsonResponse($this->client->getResponse());
160
        $this->assertJsonStringEqualsJsonString(
161
            json_encode($group),
162
            $this->getResponseContent(true)
163
        );
164
    }
165
    
166 View Code Duplication
    public function testUpdateGroupInsufficentPerms()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
    {
168
        $this->logIn('ROLE_USER');
169
        $this->client->request('PUT', '/api/groups/' . TestGroupFixtures::$groups['group-2']->getId());
170
        
171
        $this->assertForbidden($this->client->getResponse());
172
    }
173
    
174 View Code Duplication
    public function testUpdateGroupInvalidGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176
        $this->logIn('ROLE_SUPER_ADMIN');
177
        $this->client->request('PUT', '/api/groups/1000');
178
        
179
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
180
    }
181
    
182 View Code Duplication
    public function testDeleteGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
183
    {
184
        $this->logIn('ROLE_SUPER_ADMIN');
185
        $this->client->request('DELETE', '/api/groups/' . TestGroupFixtures::$groups['group-3']->getId());
186
        
187
        $this->assertEquals(Response::HTTP_NO_CONTENT, $this->client->getResponse()->getStatusCode());
188
        $this->assertNull($this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-3']->getId()));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
189
    }
190
    
191 View Code Duplication
    public function testDeleteGroupPopulatedGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
192
    {
193
        $this->logIn('ROLE_SUPER_ADMIN');
194
        $this->client->request('DELETE', '/api/groups/' . TestGroupFixtures::$groups['group-2']->getId());
195
        
196
        $this->assertEquals(Response::HTTP_UNPROCESSABLE_ENTITY, $this->client->getResponse()->getStatusCode());
197
        $this->assertNotNull($this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-2']->getId()));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
198
    }
199
    
200
    public function testDeleteGroupInsufficentPerms()
201
    {
202
        $this->logIn('ROLE_ADMIN');
203
        $this->client->request('DELETE', '/api/groups/' . TestGroupFixtures::$groups['group-3']->getId());
204
        
205
        $this->assertForbidden($this->client->getResponse());
206
        $this->assertNotNull($this->em->find("Overwatch\TestBundle\Entity\TestGroup", TestGroupFixtures::$groups['group-2']->getId()));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
207
    }
208
    
209 View Code Duplication
    public function testDeleteGroupInvalidGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
210
    {
211
        $this->logIn('ROLE_SUPER_ADMIN');
212
        $this->client->request('DELETE', '/api/groups/1000');
213
        
214
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
215
    }
216
    
217 View Code Duplication
    public function testAddUserToGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
218
    {
219
        $user = UserFixtures::$users['user-2'];
220
        $group = TestGroupFixtures::$groups['group-3'];
221
        
222
        $this->logIn('ROLE_SUPER_ADMIN');
223
        $this->client->request('POST', '/api/groups/' . $group->getId() . '/user/' . $user->getId());
224
        
225
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
226
        
227
        $this->assertJsonResponse($this->client->getResponse());
228
        $this->assertJsonStringEqualsJsonString(json_encode($user), $this->getResponseContent(true));
229
        $this->assertCount(1, $group->getUsers());
230
    }
231
    
232
    public function testAddUserToGroupInsufficentPerms()
233
    {
234
        $user = UserFixtures::$users['user-2'];
235
        $group = TestGroupFixtures::$groups['group-3'];
236
        
237
        $this->logIn('ROLE_ADMIN');
238
        $this->client->request('POST', '/api/groups/' . $group->getId() . '/user/' . $user->getId());
239
        
240
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
241
        
242
        $this->assertForbidden($this->client->getResponse());
243
        $this->assertCount(0, $group->getUsers());
244
    }
245
    
246
    public function testAddUserToGroupInvalidGroup()
247
    {
248
        $user = UserFixtures::$users['user-2'];
249
        
250
        $this->logIn('ROLE_SUPER_ADMIN');
251
        $this->client->request('POST', '/api/groups/1000/user/' . $user->getId());
252
        
253
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
254
    }
255
    
256 View Code Duplication
    public function testAddUserToGroupInvalidUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
257
    {
258
        $group = TestGroupFixtures::$groups['group-3'];
259
        
260
        $this->logIn('ROLE_SUPER_ADMIN');
261
        $this->client->request('POST', '/api/groups/' . $group->getId() . '/user/1000');
262
        
263
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
264
        
265
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
266
        $this->assertCount(0, $group->getUsers());
267
    }
268
    
269 View Code Duplication
    public function testRemoveUserFromGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
    {
271
        $user = UserFixtures::$users['user-2'];
272
        $group = TestGroupFixtures::$groups['group-1'];
273
        
274
        $this->logIn('ROLE_SUPER_ADMIN');
275
        $this->client->request('DELETE', '/api/groups/' . $group->getId() . '/user/' . $user->getId());
276
        
277
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
278
        
279
        $this->assertJsonResponse($this->client->getResponse());
280
        $this->assertJsonStringEqualsJsonString(json_encode($user), $this->getResponseContent(true));
281
        $this->assertCount(1, $group->getUsers());
282
    }
283
    
284
    public function testRemoveUserFromGroupInsufficentPerms()
285
    {
286
        $user = UserFixtures::$users['user-2'];
287
        $group = TestGroupFixtures::$groups['group-1'];
288
        
289
        $this->logIn('ROLE_ADMIN');
290
        $this->client->request('DELETE', '/api/groups/' . $group->getId() . '/user/' . $user->getId());
291
        
292
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
293
        
294
        $this->assertForbidden($this->client->getResponse());
295
        $this->assertCount(2, $group->getUsers());
296
    }
297
    
298 View Code Duplication
    public function testRemoveUserFromGroupInvalidGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
299
    {
300
        $user = UserFixtures::$users['user-2'];
301
        $group = TestGroupFixtures::$groups['group-1'];
302
        
303
        $this->logIn('ROLE_SUPER_ADMIN');
304
        $this->client->request('DELETE', '/api/groups/1000/user/' . $user->getId());
305
        
306
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
307
        
308
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
309
        $this->assertCount(2, $group->getUsers());
310
    }
311
    
312 View Code Duplication
    public function testRemoveUserFromGroupInvalidUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
313
    {
314
        $group = TestGroupFixtures::$groups['group-1'];
315
        
316
        $this->logIn('ROLE_SUPER_ADMIN');
317
        $this->client->request('DELETE', '/api/groups/' . $group->getId() . '/user/1000');
318
        
319
        $group = $this->em->find("Overwatch\TestBundle\Entity\TestGroup", $group->getId());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Overwatch\TestBundle\Entity\TestGroup does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
320
        
321
        $this->assertEquals(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
322
        $this->assertCount(2, $group->getUsers());
323
    }
324
}
325