Completed
Push — master ( 6ceb07...e22522 )
by Sergei
16:21
created

Functional/Controller/GroupsControllerTest.php (28 issues)

Upgrade to new PHP Analysis Engine

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 Modera\BackendSecurityBundle\Tests\Functional\Controller;
4
5
use Doctrine\ORM\Tools\SchemaTool;
6
use Modera\BackendSecurityBundle\Controller\GroupsController;
7
use Modera\FoundationBundle\Testing\FunctionalTestCase;
8
use Modera\SecurityBundle\Entity\Group;
9
use Modera\SecurityBundle\Entity\Permission;
10
use Modera\SecurityBundle\Entity\PermissionCategory;
11
use Modera\SecurityBundle\Entity\User;
12
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
13
14
/**
15
 * @author    Alex Plaksin <[email protected]>
16
 * @copyright 2016 Modera Foundation
17
 */
18
class GroupsControllerTest extends FunctionalTestCase
19
{
20
    /**
21
     * @var SchemaTool
22
     */
23
    private static $schemaTool;
24
25
    private static $encoder;
26
27
    /**
28
     * @var User
29
     */
30
    private static $user;
31
32
    /**
33
     * @var GroupsController
34
     */
35
    private static $controller;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function doSetUpBeforeClass()
41
    {
42
        static::$schemaTool = new SchemaTool(static::$em);
0 ignored issues
show
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...
43
        static::$schemaTool->dropSchema(static::getTablesMetadata());
0 ignored issues
show
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...
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...
44
        static::$schemaTool->createSchema(static::getTablesMetadata());
0 ignored issues
show
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...
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...
45
46
        static::$encoder = static::$container->get('security.encoder_factory');
0 ignored issues
show
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...
47
48
        static::$user = new User();
0 ignored issues
show
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...
49
        static::$user->setEmail('[email protected]');
0 ignored issues
show
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
        static::$user->setPassword(
0 ignored issues
show
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...
51
            static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt())
0 ignored issues
show
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...
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...
52
        );
53
        static::$user->setUsername('testUser');
0 ignored issues
show
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...
54
55
        $entityPermissionCategory = new PermissionCategory();
56
        $entityPermissionCategory->setName('backend_user');
57
        $entityPermissionCategory->setTechnicalName('backend_user');
58
        static::$em->persist($entityPermissionCategory);
59
60
        $entityPermission = new Permission();
61
        $entityPermission->setRoleName('IS_AUTHENTICATED_FULLY');
62
        $entityPermission->setDescription('IS_AUTHENTICATED_FULLY');
63
        $entityPermission->setName('IS_AUTHENTICATED_FULLY');
64
        $entityPermission->setCategory($entityPermissionCategory);
65
66
        $entityPermission2 = new Permission();
67
        $entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS');
68
        $entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS');
69
        $entityPermission2->setName('ROLE_MANAGE_PERMISSIONS');
70
        $entityPermission2->setCategory($entityPermissionCategory);
71
72
        $entityPermission3 = new Permission();
73
        $entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
74
        $entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
75
        $entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
76
        $entityPermission3->setCategory($entityPermissionCategory);
77
78
        static::$em->persist($entityPermission);
79
        static::$em->persist($entityPermission2);
80
        static::$em->persist($entityPermission3);
81
        static::$em->flush();
82
83
        $group = new Group();
84
        $group->setRefName('BACKEND-USER');
85
        $group->setName('backend-user');
86
        $group->addPermission($entityPermission);
87
        $group->addPermission($entityPermission2);
88
        $group->addPermission($entityPermission3);
89
90
        static::$user->addToGroup($group);
0 ignored issues
show
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...
91
92
        static::$em->persist($group);
93
        static::$em->persist(static::$user);
0 ignored issues
show
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...
94
95
        static::$em->flush();
96
97
        static::$controller = new GroupsController();
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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
        static::$controller->setContainer(static::$container);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
99
    }
100
101
    public function doSetUp()
102
    {
103
        $token = new UsernamePasswordToken(static::$user, '1234', 'secured_area');
0 ignored issues
show
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...
104
105
        static::$container->get('security.token_storage')->setToken($token);
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public static function doTearDownAfterClass()
112
    {
113
        static::$schemaTool->dropSchema(static::getTablesMetadata());
0 ignored issues
show
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...
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...
114
    }
115
116
    /**
117
     * Simple correct behavior group create.
118
     *
119
     * @return null|object
120
     */
121
    public function testCreateAction()
122
    {
123
        $beforeGroupsCount = count(static::$em->getRepository(Group::clazz())->findAll());
124
125
        $params = array(
126
            'record' => array(
127
                'id' => '',
128
                'name' => 'testName',
129
                'refName' => 'testRefName',
130
            ),
131
        );
132
133
        $result = static::$controller->createAction($params);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
134
135
        $this->assertArrayHasKey('success', $result);
136
        $this->assertTrue($result['success']);
137
        $this->assertArrayHasKey('created_models', $result);
138
        $this->assertArrayHasKey('modera.security_bundle.group', $result['created_models']);
139
        $this->assertCount(1, $result['created_models']['modera.security_bundle.group']);
140
141
        $afterGroupsCount = count(static::$em->getRepository(Group::clazz())->findAll());
142
        $this->assertEquals($beforeGroupsCount + 1, $afterGroupsCount);
143
144
        $createdGroup = static::$em->getRepository(Group::clazz())->find($result['created_models']['modera.security_bundle.group'][0]);
145
146
        $this->assertEquals('testName', $createdGroup->getName());
147
        $this->assertEquals('TESTREFNAME', $createdGroup->getRefName());
148
149
        return $createdGroup;
150
    }
151
152
    /**
153
     * @depends testCreateAction
154
     */
155 View Code Duplication
    public function testCreateAction_EmptyName()
0 ignored issues
show
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...
156
    {
157
        $params = array(
158
            'record' => array(
159
                'id' => '',
160
                'name' => '',
161
                'refName' => '',
162
            ),
163
        );
164
165
        $result = static::$controller->createAction($params);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
166
167
        $this->assertArrayHasKey('success', $result);
168
        $this->assertFalse($result['success']);
169
        $this->assertArrayHasKey('field_errors', $result);
170
        $this->assertCount(1, $result['field_errors']);
171
        $this->assertArrayHasKey('name', $result['field_errors']);
172
    }
173
174
    /**
175
     * @depends testCreateAction
176
     */
177 View Code Duplication
    public function testCreateAction_DuplicatedRefName()
0 ignored issues
show
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...
178
    {
179
        $params = array(
180
            'record' => array(
181
                'id' => '',
182
                'name' => 'testName2',
183
                'refName' => 'testRefName',
184
            ),
185
        );
186
187
        $result = static::$controller->createAction($params);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
188
189
        $this->assertArrayHasKey('success', $result);
190
        $this->assertFalse($result['success']);
191
        $this->assertArrayHasKey('field_errors', $result);
192
        $this->assertCount(1, $result['field_errors']);
193
        $this->assertArrayHasKey('refName', $result['field_errors']);
194
    }
195
196
    /**
197
     * @depends testCreateAction
198
     */
199
    public function testUpdateAction(Group $group)
200
    {
201
        $params = array(
202
            'record' => array(
203
                'id' => $group->getId(),
204
                'name' => 'testNameUpdated',
205
                'refName' => 'testRefNameUpdated',
206
            ),
207
        );
208
209
        $result = static::$controller->updateAction($params);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
210
211
        $this->assertArrayHasKey('success', $result);
212
        $this->assertTrue($result['success']);
213
        $this->assertArrayHasKey('updated_models', $result);
214
        $this->assertArrayHasKey('modera.security_bundle.group', $result['updated_models']);
215
        $this->assertCount(1, $result['updated_models']['modera.security_bundle.group']);
216
        $this->assertEquals($group->getId(), $result['updated_models']['modera.security_bundle.group'][0]);
217
218
        /** @var Group $groupFromDb */
219
        $groupFromDb = static::$em->find(Group::clazz(), $group->getId());
220
221
        $this->assertEquals('testNameUpdated', $groupFromDb->getName());
222
        $this->assertEquals('TESTREFNAMEUPDATED', $groupFromDb->getRefName());
223
    }
224
225
    /**
226
     * @depends testCreateAction
227
     * @depends testUpdateAction
228
     *
229
     * @param Group $group
230
     *
231
     * @return Group
232
     */
233
    public function testUpdateAction_SameRefName(Group $group)
234
    {
235
        $this->assertEquals('TESTREFNAMEUPDATED', $group->getRefName());
236
237
        $params = array(
238
            'record' => array(
239
                'id' => $group->getId(),
240
                'name' => 'newTestName',
241
                'refName' => 'testRefNameUpdated',
242
            ),
243
        );
244
245
        $result = static::$controller->updateAction($params);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
246
247
        $this->assertArrayHasKey('success', $result);
248
        $this->assertTrue($result['success']);
249
        $this->assertArrayHasKey('updated_models', $result);
250
        $this->assertArrayHasKey('modera.security_bundle.group', $result['updated_models']);
251
        $this->assertCount(1, $result['updated_models']['modera.security_bundle.group']);
252
        $this->assertEquals($group->getId(), $result['updated_models']['modera.security_bundle.group'][0]);
253
254
        /** @var Group $groupFromDb */
255
        $groupFromDb = static::$em->find(Group::clazz(), $group->getId());
256
257
        $this->assertEquals('newTestName', $groupFromDb->getName());
258
        $this->assertEquals('TESTREFNAMEUPDATED', $groupFromDb->getRefName());
259
260
        return $groupFromDb;
261
    }
262
263
    /**
264
     * @depends testUpdateAction_SameRefName
265
     *
266
     * @param Group $group
267
     */
268
    public function testUpdateAction_ExistingRefNameUse(Group $group)
269
    {
270
        $newGroup = new Group();
271
        $newGroup->setName('brandNewGroup');
272
        $newGroup->setRefName('brandNewRefName');
273
274
        static::$em->persist($newGroup);
275
        static::$em->flush();
276
277
        $this->assertEquals('TESTREFNAMEUPDATED', $group->getRefName());
278
279
        $params = array(
280
            'record' => array(
281
                'id' => $group->getId(),
282
                'name' => 'newTestNameExistingRef',
283
                'refName' => 'brandNewRefName',
284
            ),
285
        );
286
287
        $result = static::$controller->updateAction($params);
0 ignored issues
show
Since $controller is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $controller 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...
288
289
        $this->assertArrayHasKey('success', $result);
290
        $this->assertFalse($result['success']);
291
        $this->assertArrayHasKey('field_errors', $result);
292
        $this->assertCount(1, $result['field_errors']);
293
        $this->assertArrayHasKey('refName', $result['field_errors']);
294
    }
295
296
    /**
297
     * @return array
298
     */
299
    private static function getTablesClasses()
300
    {
301
        return array(
302
            Permission::clazz(),
303
            PermissionCategory::clazz(),
304
            User::clazz(),
305
            Group::clazz(),
306
        );
307
    }
308
309
    private static function getTablesMetadata()
310
    {
311
        $metaData = array();
312
313
        foreach (static::getTablesClasses() as $class) {
0 ignored issues
show
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...
314
            $metaData[] = static::$em->getClassMetadata($class);
315
        }
316
317
        return $metaData;
318
    }
319
320
    /**
321
     * {@inheritdoc}
322
     */
323
    protected static function getIsolationLevel()
324
    {
325
        return self::IM_CLASS;
326
    }
327
}
328