Completed
Push — master ( e22522...ee64fa )
by Sergei
13:37
created

UsersControllerTest::getTablesClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Modera\BackendSecurityBundle\Tests\Functional\Controller;
4
5
use Doctrine\ORM\Tools\SchemaTool;
6
use Modera\ActivityLoggerBundle\Entity\Activity;
7
use Modera\BackendSecurityBundle\Controller\UsersController;
8
use Modera\FoundationBundle\Testing\FunctionalTestCase;
9
use Modera\SecurityBundle\Entity\Group;
10
use Modera\SecurityBundle\Entity\Permission;
11
use Modera\SecurityBundle\Entity\PermissionCategory;
12
use Modera\SecurityBundle\Entity\User;
13
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
14
15
/**
16
 * @author    Alex Plaksin <[email protected]>
17
 * @copyright 2016 Modera Foundation
18
 */
19
class UsersControllerTest extends FunctionalTestCase
20
{
21
    /**
22
     * @var SchemaTool
23
     */
24
    private static $schemaTool;
25
26
    private static $encoder;
27
28
    /**
29
     * @var User
30
     */
31
    private static $user;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public static function doSetUpBeforeClass()
37
    {
38
        static::$schemaTool = new SchemaTool(static::$em);
0 ignored issues
show
Bug introduced by
Since $schemaTool is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $schemaTool to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
39
        static::$schemaTool->dropSchema(static::getTablesMetadata());
0 ignored issues
show
Bug introduced by
Since $schemaTool is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $schemaTool to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
Since getTablesMetadata() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getTablesMetadata() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
40
        static::$schemaTool->createSchema(static::getTablesMetadata());
0 ignored issues
show
Bug introduced by
Since $schemaTool is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $schemaTool to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
Since getTablesMetadata() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getTablesMetadata() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
41
42
        static::$encoder = static::$container->get('security.encoder_factory');
0 ignored issues
show
Bug introduced by
Since $encoder is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $encoder to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
43
44
        static::$user = new User();
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
45
        static::$user->setEmail('[email protected]');
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
46
        static::$user->setPassword(
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
47
            static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt())
0 ignored issues
show
Bug introduced by
Since $encoder is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $encoder to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
48
        );
49
        static::$user->setUsername('testUser');
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
50
51
        $entityPermissionCategory = new PermissionCategory();
52
        $entityPermissionCategory->setName('backend_user');
53
        $entityPermissionCategory->setTechnicalName('backend_user');
54
        static::$em->persist($entityPermissionCategory);
55
56
        $entityPermission = new Permission();
57
        $entityPermission->setRoleName('IS_AUTHENTICATED_FULLY');
58
        $entityPermission->setDescription('IS_AUTHENTICATED_FULLY');
59
        $entityPermission->setName('IS_AUTHENTICATED_FULLY');
60
        $entityPermission->setCategory($entityPermissionCategory);
61
62
        $entityPermission2 = new Permission();
63
        $entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS');
64
        $entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS');
65
        $entityPermission2->setName('ROLE_MANAGE_PERMISSIONS');
66
        $entityPermission2->setCategory($entityPermissionCategory);
67
68
        $entityPermission3 = new Permission();
69
        $entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
70
        $entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
71
        $entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
72
        $entityPermission3->setCategory($entityPermissionCategory);
73
74
        $entityPermission4 = new Permission();
75
        $entityPermission4->setRoleName('ROLE_MANAGE_USER_PROFILES');
76
        $entityPermission4->setDescription('ROLE_MANAGE_USER_PROFILES');
77
        $entityPermission4->setName('ROLE_MANAGE_USER_PROFILES');
78
        $entityPermission4->setCategory($entityPermissionCategory);
79
80
        static::$em->persist($entityPermission);
81
        static::$em->persist($entityPermission2);
82
        static::$em->persist($entityPermission3);
83
        static::$em->persist($entityPermission4);
84
        static::$em->flush();
85
86
        $group = new Group();
87
        $group->setRefName('BACKEND-USER');
88
        $group->setName('backend-user');
89
        $group->addPermission($entityPermission);
90
        $group->addPermission($entityPermission2);
91
        $group->addPermission($entityPermission3);
92
        $group->addPermission($entityPermission4);
93
94
        static::$user->addToGroup($group);
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
95
96
        static::$em->persist($group);
97
        static::$em->persist(static::$user);
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
98
99
        static::$em->flush();
100
    }
101
102
    public function testMainFormHydration()
103
    {
104
        $this->assertNotNull(static::$user);
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
105
106
        $user = static::$em->find(User::clazz(), static::$user->getId());
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
107
108
        $this->assertNotNull($user);
109
110
        $this->assertEquals(static::$user, $user);
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
111
112
        $userMeta = array('rootElement' => array('subElement' => 'subElementValue', 'subElement2' => 'subElementValue2'),
113
        );
114
        static::$user->setMeta($userMeta);
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
115
116
        static::$em->flush();
117
118
        $controller = $this->getController();
119
120
        $response = $controller->listAction(
121
            array(
122
                'hydration' => array('profile' => 'list'),
123
                'page' => 1,
124
                'start' => 0,
125
                'limit' => 25,
126
            )
127
        );
128
129
        $this->assertArrayHasKey('success', $response);
130
        $this->assertArrayHasKey('total', $response);
131
        $this->assertArrayHasKey('items', $response);
132
133
        //assuming this is first test in file
134
        $this->assertGreaterThanOrEqual(1, count($response['items']));
135
136
        $hydratedUser = $response['items'][0];
137
        $this->assertArrayHasKey('id', $hydratedUser);
138
        $this->assertArrayHasKey('username', $hydratedUser);
139
        $this->assertArrayHasKey('email', $hydratedUser);
140
        $this->assertArrayHasKey('firstName', $hydratedUser);
141
        $this->assertArrayHasKey('lastName', $hydratedUser);
142
        $this->assertArrayHasKey('middleName', $hydratedUser);
143
        $this->assertArrayHasKey('state', $hydratedUser);
144
        $this->assertArrayHasKey('groups', $hydratedUser);
145
        $this->assertCount(1, $hydratedUser['groups']);
146
        $this->assertArrayHasKey('meta', $hydratedUser);
147
        $this->assertEquals($userMeta, $hydratedUser['meta']);
148
    }
149
150
    public function testIsMetaInfoStoredOnCreation()
151
    {
152
        $userMeta = array(
153
            'modera_backend_service_account_plugin' => array(
154
                'isService' => true,
155
                'password' => '1234',
156
            ),
157
        );
158
159
        $params = array(
160
            'record' => array(
161
                'id' => '',
162
                'lastName' => 'Full Display Name',
163
                'username' => 'serviceAccount',
164
                'email' => '[email protected]',
165
                'meta' => $userMeta,
166
            ),
167
        );
168
169
        $controller = $this->getController();
170
171
        $response = $controller->createAction($params);
172
173
        $this->assertTrue($response['success']);
174
        /*
175
         * @var User[]
176
         */
177
        $userList = static::$em->getRepository(User::clazz())->findAll();
178
179
        $lastUser = array_pop($userList);
180
181
        $this->assertEquals('[email protected]', $lastUser->getEmail());
182
        $this->assertEquals($userMeta, $lastUser->getMeta());
183
184
        return $lastUser;
185
    }
186
187
    public function testIsMetaInfoStoredOnCreation_NoMeta()
188
    {
189
        $params = array(
190
            'record' => array(
191
                'id' => '',
192
                'lastName' => 'Full Display Name',
193
                'username' => 'serviceAccount_NoMeta',
194
                'email' => '[email protected]',
195
                'meta' => '',
196
            ),
197
        );
198
199
        $controller = $this->getController();
200
201
        $response = $controller->createAction($params);
202
203
        $this->assertTrue($response['success']);
204
        /*
205
         * @var User[]
206
         */
207
        $userList = static::$em->getRepository(User::clazz())->findAll();
208
209
        $lastUser = array_pop($userList);
210
211
        $this->assertEquals('[email protected]', $lastUser->getEmail());
212
        $this->assertEquals(array(), $lastUser->getMeta());
213
214
        return $lastUser;
215
    }
216
217
    /**
218
     * @depends testIsMetaInfoStoredOnCreation
219
     *
220
     * @param User $user
221
     */
222
    public function testIsMetaInfoStoredOnUpdate(User $user)
223
    {
224
        $userMeta = array(
225
            'modera_backend_service_account_plugin' => array(
226
                'isService' => true,
227
                'password' => '5678',
228
            ),
229
        );
230
231
        $params = array(
232
            'record' => array(
233
                'id' => $user->getId(),
234
                'lastName' => $user->getLastName(),
235
                'username' => $user->getUsername(),
236
                'email' => $user->getEmail(),
237
                'meta' => $userMeta,
238
            ),
239
        );
240
241
        $controller = $this->getController();
242
243
        $response = $controller->updateAction($params);
244
245
        $this->assertTrue($response['success']);
246
        /*
247
         * @var User[] $userList
248
         */
249
        $userFromDb = static::$em->getRepository(User::clazz())->find($user->getId());
250
251
        $this->assertEquals('[email protected]', $userFromDb->getEmail());
252
        $this->assertEquals($userMeta, $userFromDb->getMeta());
253
    }
254
255
    /**
256
     * @depends testIsMetaInfoStoredOnCreation
257
     *
258
     * @param User $user
259
     */
260
    public function testIsMetaStoredOnUpdate_NoMeta(User $user)
261
    {
262
        $params = array(
263
            'record' => array(
264
                'id' => $user->getId(),
265
                'lastName' => $user->getLastName(),
266
                'username' => $user->getUsername(),
267
                'email' => $user->getEmail(),
268
                'meta' => '',
269
            ),
270
        );
271
272
        $controller = $this->getController();
273
274
        $response = $controller->updateAction($params);
275
276
        $this->assertTrue($response['success']);
277
        /*
278
         * @var User[]
279
         */
280
        $userList = static::$em->getRepository(User::clazz())->findAll();
281
282
        $lastUser = array_pop($userList);
0 ignored issues
show
Unused Code introduced by
$lastUser is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
283
284
        $this->assertEquals('[email protected]', $user->getEmail());
285
        $this->assertTrue(is_array($user->getMeta()));
286
        $this->assertCount(0, $user->getMeta());
287
    }
288
289
    public function doSetUp()
290
    {
291
        $token = new UsernamePasswordToken(static::$user, '1234', 'secured_area');
0 ignored issues
show
Bug introduced by
Since $user is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
292
293
        static::$container->get('security.token_storage')->setToken($token);
294
    }
295
296
    /**
297
     * @return UsersController
298
     */
299
    private function getController()
300
    {
301
        $controller = new UsersController();
302
        $controller->setContainer(static::$container);
303
304
        return $controller;
305
    }
306
307
    /**
308
     * @return array
309
     */
310
    private static function getTablesClasses()
311
    {
312
        return array(
313
            Permission::clazz(),
314
            PermissionCategory::clazz(),
315
            User::clazz(),
316
            Group::clazz(),
317
            Activity::clazz(),
318
        );
319
    }
320
321 View Code Duplication
    private static function getTablesMetadata()
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...
322
    {
323
        $metaData = array();
324
325
        foreach (static::getTablesClasses() as $class) {
0 ignored issues
show
Bug introduced by
Since getTablesClasses() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getTablesClasses() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
326
            $metaData[] = static::$em->getClassMetadata($class);
327
        }
328
329
        return $metaData;
330
    }
331
332
    /**
333
     * {@inheritdoc}
334
     */
335
    protected static function getIsolationLevel()
336
    {
337
        return self::IM_CLASS;
338
    }
339
}
340