Completed
Push — master ( 6c1318...fd4dfb )
by Mahmoud
03:00
created

testAttachSinglePermissionToRole_()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 31
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\Order\UI\API\Tests\Functional;
4
5
use App\Containers\Authorization\Models\Permission;
6
use App\Containers\Authorization\Models\Role;
7
use App\Containers\User\Models\User;
8
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
9
10
/**
11
 * Class AttachPermissionsToRoleTest.
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
class AttachPermissionsToRoleTest extends TestCase
16
{
17
18
    private $endpoint = '/permissions/attach';
19
20
    public function testAttachSinglePermissionToRole_()
21
    {
22
        $admin = $this->getLoggedInTestingAdmin();
0 ignored issues
show
Unused Code introduced by
$admin 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...
23
24
        $roleA = Role::create([
25
            'name'         => 'role-A',
26
            'description'  => 'AA',
27
            'display_name' => 'A',
28
        ]);
29
30
        $permissionA = Permission::create([
31
            'name'         => 'permission-A',
32
            'description'  => 'AA',
33
            'display_name' => 'A',
34
        ]);
35
36
        $data = [
37
            'role_name' => $roleA['name'],
38
            'permission_name' => $permissionA['name'],
39
        ];
40
41
        // send the HTTP request
42
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
43
44
        // assert response status is correct
45
        $this->assertEquals($response->getStatusCode(), '200');
46
47
        $responseObject = $this->getResponseObject($response);
48
49
        $this->assertEquals($roleA['name'], $responseObject->data->name);
50
    }
51
52
    public function testAttachMultiplePermissionToRole_()
53
    {
54
        $admin = $this->getLoggedInTestingAdmin();
0 ignored issues
show
Unused Code introduced by
$admin 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...
55
56
        $roleA = Role::create([
57
            'name'         => 'role-A',
58
            'description'  => 'AA',
59
            'display_name' => 'A',
60
        ]);
61
62
        $permissionA = Permission::create([
63
            'name'         => 'permission-A',
64
            'description'  => 'AA',
65
            'display_name' => 'A',
66
        ]);
67
68
        $permissionB = Permission::create([
69
            'name'         => 'permission-B',
70
            'description'  => 'BB',
71
            'display_name' => 'B',
72
        ]);
73
74
75
        $data = [
76
            'role_name' => $roleA['name'],
77
            'permission_name' => [$permissionA['name'], $permissionB['name']]
78
        ];
79
80
        // send the HTTP request
81
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
82
83
        // assert response status is correct
84
        $this->assertEquals($response->getStatusCode(), '200');
85
86
    }
87
88
89
}
90