Completed
Push — master ( 29f90c...6ceb07 )
by Sergei
02:28
created

GroupsControllerTest::testUpdateAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 16
nc 1
nop 1
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
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...
43
        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...
44
        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...
45
46
        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...
47
48
        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...
49
        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...
50
        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...
51
            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...
52
        );
53
        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...
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
89
        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...
90
91
        static::$em->persist($group);
92
        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...
93
94
        static::$em->flush();
95
96
        static::$controller = new GroupsController();
0 ignored issues
show
Bug introduced by
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...
97
        static::$controller->setContainer(static::$container);
0 ignored issues
show
Bug introduced by
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
    }
99
100
    public function doSetUp()
101
    {
102
        $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...
103
104
        static::$container->get('security.token_storage')->setToken($token);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public static function doTearDownAfterClass()
111
    {
112
        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...
113
    }
114
115
    /**
116
     * Simple correct behavior group create.
117
     *
118
     * @return null|object
119
     */
120
    public function testCreateAction()
121
    {
122
        $beforeGroupsCount = count(static::$em->getRepository(Group::clazz())->findAll());
123
124
        $params = array(
125
            'record' => array(
126
                'id' => '',
127
                'name' => 'testName',
128
                'refName' => 'testRefName',
129
            ),
130
        );
131
132
        $result = static::$controller->createAction($params);
0 ignored issues
show
Bug introduced by
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...
133
134
        $this->assertArrayHasKey('success', $result);
135
        $this->assertTrue($result['success']);
136
        $this->assertArrayHasKey('created_models', $result);
137
        $this->assertArrayHasKey('modera.security_bundle.group', $result['created_models']);
138
        $this->assertCount(1, $result['created_models']['modera.security_bundle.group']);
139
140
        $afterGroupsCount = count(static::$em->getRepository(Group::clazz())->findAll());
141
        $this->assertEquals($beforeGroupsCount + 1, $afterGroupsCount);
142
143
        $createdGroup = static::$em->getRepository(Group::clazz())->find($result['created_models']['modera.security_bundle.group'][0]);
144
145
        $this->assertEquals('testName', $createdGroup->getName());
146
        $this->assertEquals('testRefName', $createdGroup->getRefName());
147
148
        return $createdGroup;
149
    }
150
151
    /**
152
     * @depends testCreateAction
153
     */
154 View Code Duplication
    public function testCreateAction_EmptyName()
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...
155
    {
156
        $params = array(
157
            'record' => array(
158
                'id' => '',
159
                'name' => '',
160
                'refName' => '',
161
            ),
162
        );
163
164
        $result = static::$controller->createAction($params);
0 ignored issues
show
Bug introduced by
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...
165
166
        $this->assertArrayHasKey('success', $result);
167
        $this->assertFalse($result['success']);
168
        $this->assertArrayHasKey('field_errors', $result);
169
        $this->assertCount(1, $result['field_errors']);
170
        $this->assertArrayHasKey('name', $result['field_errors']);
171
    }
172
173
    /**
174
     * @depends testCreateAction
175
     */
176 View Code Duplication
    public function testCreateAction_DuplicatedRefName()
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...
177
    {
178
        $params = array(
179
            'record' => array(
180
                'id' => '',
181
                'name' => 'testName2',
182
                'refName' => 'testRefName',
183
            ),
184
        );
185
186
        $result = static::$controller->createAction($params);
0 ignored issues
show
Bug introduced by
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...
187
188
        $this->assertArrayHasKey('success', $result);
189
        $this->assertFalse($result['success']);
190
        $this->assertArrayHasKey('field_errors', $result);
191
        $this->assertCount(1, $result['field_errors']);
192
        $this->assertArrayHasKey('refName', $result['field_errors']);
193
    }
194
195
    /**
196
     * @depends testCreateAction
197
     */
198
    public function testUpdateAction(Group $group)
199
    {
200
        $params = array(
201
            'record' => array(
202
                'id' => $group->getId(),
203
                'name' => 'testNameUpdated',
204
                'refName' => 'testRefNameUpdated',
205
            ),
206
        );
207
208
        $result = static::$controller->updateAction($params);
0 ignored issues
show
Bug introduced by
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...
209
210
        $this->assertArrayHasKey('success', $result);
211
        $this->assertTrue($result['success']);
212
        $this->assertArrayHasKey('updated_models', $result);
213
        $this->assertArrayHasKey('modera.security_bundle.group', $result['updated_models']);
214
        $this->assertCount(1, $result['updated_models']['modera.security_bundle.group']);
215
        $this->assertEquals($group->getId(), $result['updated_models']['modera.security_bundle.group'][0]);
216
217
        /** @var Group $groupFromDb */
218
        $groupFromDb = static::$em->find(Group::clazz(), $group->getId());
219
220
        $this->assertEquals('testNameUpdated', $groupFromDb->getName());
221
        $this->assertEquals('testRefNameUpdated', $groupFromDb->getRefName());
222
    }
223
224
    /**
225
     * @depends testCreateAction
226
     * @depends testUpdateAction
227
     *
228
     * @param Group $group
229
     *
230
     * @return Group
231
     */
232
    public function testUpdateAction_SameRefName(Group $group)
233
    {
234
        $this->assertEquals('testRefNameUpdated', $group->getRefName());
235
236
        $params = array(
237
            'record' => array(
238
                'id' => $group->getId(),
239
                'name' => 'newTestName',
240
                'refName' => 'testRefNameUpdated',
241
            ),
242
        );
243
244
        $result = static::$controller->updateAction($params);
0 ignored issues
show
Bug introduced by
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...
245
246
        $this->assertArrayHasKey('success', $result);
247
        $this->assertTrue($result['success']);
248
        $this->assertArrayHasKey('updated_models', $result);
249
        $this->assertArrayHasKey('modera.security_bundle.group', $result['updated_models']);
250
        $this->assertCount(1, $result['updated_models']['modera.security_bundle.group']);
251
        $this->assertEquals($group->getId(), $result['updated_models']['modera.security_bundle.group'][0]);
252
253
        /** @var Group $groupFromDb */
254
        $groupFromDb = static::$em->find(Group::clazz(), $group->getId());
255
256
        $this->assertEquals('newTestName', $groupFromDb->getName());
257
        $this->assertEquals('testRefNameUpdated', $groupFromDb->getRefName());
258
259
        return $groupFromDb;
260
    }
261
262
    /**
263
     * @depends testUpdateAction_SameRefName
264
     *
265
     * @param Group $group
266
     */
267
    public function testUpdateAction_ExistingRefNameUse(Group $group)
268
    {
269
        $newGroup = new Group();
270
        $newGroup->setName('brandNewGroup');
271
        $newGroup->setRefName('brandNewRefName');
272
273
        static::$em->persist($newGroup);
274
        static::$em->flush();
275
276
        $this->assertEquals('testRefNameUpdated', $group->getRefName());
277
278
        $params = array(
279
            'record' => array(
280
                'id' => $group->getId(),
281
                'name' => 'newTestNameExistingRef',
282
                'refName' => 'brandNewRefName',
283
            ),
284
        );
285
286
        $result = static::$controller->updateAction($params);
0 ignored issues
show
Bug introduced by
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...
287
288
        $this->assertArrayHasKey('success', $result);
289
        $this->assertFalse($result['success']);
290
        $this->assertArrayHasKey('field_errors', $result);
291
        $this->assertCount(1, $result['field_errors']);
292
        $this->assertArrayHasKey('refName', $result['field_errors']);
293
    }
294
295
    /**
296
     * @return array
297
     */
298
    private static function getTablesClasses()
299
    {
300
        return array(
301
            Permission::clazz(),
302
            PermissionCategory::clazz(),
303
            User::clazz(),
304
            Group::clazz(),
305
        );
306
    }
307
308
    private static function getTablesMetadata()
309
    {
310
        $metaData = array();
311
312
        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...
313
            $metaData[] = static::$em->getClassMetadata($class);
314
        }
315
316
        return $metaData;
317
    }
318
319
    /**
320
     * {@inheritdoc}
321
     */
322
    protected static function getIsolationLevel()
323
    {
324
        return self::IM_CLASS;
325
    }
326
}
327