Code Duplication    Length = 25-27 lines in 3 locations

app/Containers/Authorization/UI/API/Tests/Functional/AttachPermissionsToRoleTest.php 1 location

@@ 24-48 (lines=25) @@
21
        'permissions' => '',
22
    ];
23
24
    public function testAttachSinglePermissionToRole_()
25
    {
26
        $roleA = factory(Role::class)->create();
27
        $permissionA = factory(Permission::class)->create();
28
29
        $data = [
30
            'role_id'         => $roleA->getHashedKey(),
31
            'permissions_ids' => [$permissionA->getHashedKey()],
32
        ];
33
34
        // send the HTTP request
35
        $response = $this->makeCall($data);
36
37
        // assert response status is correct
38
        $this->assertEquals('200', $response->getStatusCode());
39
40
        $responseContent = $this->getResponseContent($response);
41
42
        $this->assertEquals($roleA['name'], $responseContent->data->name);
43
44
        $this->seeInDatabase('role_has_permissions', [
45
            'permission_id' => $permissionA->id,
46
            'role_id'       => $roleA->id
47
        ]);
48
    }
49
50
    public function testAttachMultiplePermissionToRole_()
51
    {

app/Containers/Authorization/UI/API/Tests/Functional/DetachPermissionsFromRoleTest.php 1 location

@@ 24-50 (lines=27) @@
21
        'permissions' => '',
22
    ];
23
24
    public function testDetachSinglePermissionFromRole_()
25
    {
26
        $permissionA = factory(Permission::class)->create();
27
28
        $roleA = factory(Role::class)->create();
29
        $roleA->givePermissionTo($permissionA);
30
31
        $data = [
32
            'role_id'         => $roleA->getHashedKey(),
33
            'permissions_ids' => [$permissionA->getHashedKey()],
34
        ];
35
36
        // send the HTTP request
37
        $response = $this->makeCall($data);
38
39
        // assert response status is correct
40
        $this->assertEquals('200', $response->getStatusCode());
41
42
        $responseContent = $this->getResponseContent($response);
43
44
        $this->assertEquals($roleA->name, $responseContent->data->name);
45
46
        $this->missingFromDatabase('role_has_permissions', [
47
            'permission_id' => $permissionA->id,
48
            'role_id'       => $roleA->id
49
        ]);
50
    }
51
52
    public function testDetachMultiplePermissionFromRole_()
53
    {

app/Containers/Authorization/UI/API/Tests/Functional/RevokeUserFromRoleTest.php 1 location

@@ 24-50 (lines=27) @@
21
        'permissions' => '',
22
    ];
23
24
    public function testRevokeUserFromRole_()
25
    {
26
        $roleA = factory(Role::class)->create();
27
28
        $randomUser = factory(User::class)->create();
29
        $randomUser->assignRole($roleA);
30
31
        $data = [
32
            'roles_ids' => [$roleA->getHashedKey()],
33
            'user_id'   => $randomUser->getHashedKey(),
34
        ];
35
36
        // send the HTTP request
37
        $response = $this->makeCall($data);
38
39
        // assert response status is correct
40
        $this->assertEquals('200', $response->getStatusCode());
41
42
        $responseContent = $this->getResponseContent($response);
43
44
        $this->assertEquals($data['user_id'], $responseContent->data->id);
45
46
        $this->missingFromDatabase('user_has_roles', [
47
            'user_id' => $randomUser->id,
48
            'role_id' => $roleA->id,
49
        ]);
50
    }
51
52
    public function testRevokeUserFromRoleWithRealId_()
53
    {