CreateRoleTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateRole_() 0 20 1
A testCreateRoleWithoutLevel_() 0 18 1
A testCreateRoleWithWrongName_() 0 14 1
1
<?php
2
3
namespace App\Containers\Authorization\UI\API\Tests\Functional;
4
5
use App\Containers\Authorization\Tests\ApiTestCase;
6
7
/**
8
 * Class CreateRoleTest.
9
 *
10
 * @group authorization
11
 * @group api
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
class CreateRoleTest extends ApiTestCase
16
{
17
18
    protected $endpoint = '[email protected]/roles';
19
20
    protected $auth = true;
21
22
    protected $access = [
23
        'roles'       => '',
24
        'permissions' => 'manage-roles',
25
    ];
26
27
    public function testCreateRole_()
28
    {
29
        $data = [
30
            'name'         => 'manager',
31
            'display_name' => 'manager',
32
            'description'  => 'he manages things',
33
            'level'        => 7,
34
        ];
35
36
        // send the HTTP request
37
        $response = $this->makeCall($data);
38
39
        // assert response status is correct
40
        $response->assertStatus(200);
41
42
        $responseContent = $this->getResponseContentObject();
43
44
        $this->assertEquals($data['name'], $responseContent->data->name);
45
        $this->assertEquals($data['level'], $responseContent->data->level);
46
    }
47
48
    public function testCreateRoleWithoutLevel_()
49
    {
50
        $data = [
51
            'name'         => 'manager',
52
            'display_name' => 'manager',
53
            'description'  => 'he manages things',
54
        ];
55
56
        // send the HTTP request
57
        $response = $this->makeCall($data);
58
59
        // assert response status is correct
60
        $response->assertStatus(200);
61
62
        $responseContent = $this->getResponseContentObject();
63
64
        $this->assertEquals(0, $responseContent->data->level);
65
    }
66
67
    public function testCreateRoleWithWrongName_()
68
    {
69
        $data = [
70
            'name'         => 'include Space',
71
            'display_name' => 'manager',
72
            'description'  => 'he manages things',
73
        ];
74
75
        // send the HTTP request
76
        $response = $this->makeCall($data);
77
78
        // assert response status is correct
79
        $response->assertStatus(422);
80
    }
81
82
}
83