DetachPermissionsFromRoleTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 75
Duplicated Lines 34.67 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 26
loc 75
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDetachSinglePermissionFromRole_() 26 26 1
A testDetachMultiplePermissionFromRole_() 0 29 1

How to fix   Duplicated Code   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Containers\Authorization\UI\API\Tests\Functional;
4
5
use App\Containers\Authorization\Models\Permission;
6
use App\Containers\Authorization\Models\Role;
7
use App\Containers\Authorization\Tests\ApiTestCase;
8
9
/**
10
 * Class DetachPermissionsFromRoleTest.
11
 *
12
 * @group authorization
13
 * @group api
14
 *
15
 * @author  Mahmoud Zalt <[email protected]>
16
 */
17
class DetachPermissionsFromRoleTest extends ApiTestCase
18
{
19
20
    protected $endpoint = '[email protected]/permissions/detach';
21
22
    protected $access = [
23
        'roles'       => '',
24
        'permissions' => 'manage-roles',
25
    ];
26
27
    /**
28
     * @test
29
     */
30 View Code Duplication
    public function testDetachSinglePermissionFromRole_()
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
31
    {
32
        $permissionA = factory(Permission::class)->create();
33
34
        $roleA = factory(Role::class)->create();
35
        $roleA->givePermissionTo($permissionA);
36
37
        $data = [
38
            'role_id'         => $roleA->getHashedKey(),
39
            'permissions_ids' => [$permissionA->getHashedKey()],
40
        ];
41
42
        // send the HTTP request
43
        $response = $this->makeCall($data);
44
45
        $response->assertStatus(200);
46
47
        $responseContent = $this->getResponseContentObject();
48
49
        $this->assertEquals($roleA->name, $responseContent->data->name);
50
51
        $this->assertDatabaseMissing('role_has_permissions', [
52
            'permission_id' => $permissionA->id,
53
            'role_id'       => $roleA->id
54
        ]);
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function testDetachMultiplePermissionFromRole_()
61
    {
62
        $permissionA = factory(Permission::class)->create();
63
        $permissionB = factory(Permission::class)->create();
64
65
        $roleA = factory(Role::class)->create();
66
        $roleA->givePermissionTo($permissionA);
67
        $roleA->givePermissionTo($permissionB);
68
69
        $data = [
70
            'role_id'         => $roleA->getHashedKey(),
71
            'permissions_ids' => [$permissionA->getHashedKey(), $permissionB->getHashedKey()],
72
        ];
73
74
        // send the HTTP request
75
        $response = $this->makeCall($data);
76
77
        $response->assertStatus(200);
78
79
        $responseContent = $this->getResponseContentObject();
80
81
        $this->assertEquals($roleA->name, $responseContent->data->name);
82
83
        $this->assertDatabaseMissing('role_has_permissions', [
84
            'permission_id' => $permissionA->id,
85
            'permission_id' => $permissionB->id,
86
            'role_id'       => $roleA->id
87
        ]);
88
    }
89
90
91
}
92