SyncUserRolesTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 43
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSyncMultipleRolesOnUser() 0 31 1
1
<?php
2
3
namespace App\Containers\Authorization\UI\API\Tests\Functional;
4
5
use App\Containers\Authorization\Models\Role;
6
use App\Containers\Authorization\Tests\TestCase;
7
use App\Containers\User\Models\User;
8
9
/**
10
 * Class SyncUserRolesTest.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
class SyncUserRolesTest extends TestCase
15
{
16
17
    protected $endpoint = 'post@roles/sync';
18
19
    protected $access = [
20
        'roles'       => 'admin',
21
        'permissions' => '',
22
    ];
23
24
    public function testSyncMultipleRolesOnUser()
25
    {
26
        $role1 = factory(Role::class)->create(['display_name' => '111']);
27
        $role2 = factory(Role::class)->create(['display_name' => '222']);
28
29
        $randomUser = factory(User::class)->create();
30
        $randomUser->assignRole($role1);
31
32
33
        $data = [
34
            'roles_ids' => [
35
                $role1->getHashedKey(),
36
                $role2->getHashedKey(),
37
            ],
38
            'user_id'   => $randomUser->getHashedKey(),
39
        ];
40
41
        // send the HTTP request
42
        $response = $this->makeCall($data);
43
44
        // assert response status is correct
45
        $this->assertEquals('200', $response->getStatusCode());
46
47
        $responseContent = $this->getResponseContent($response);
48
49
        $this->assertTrue(count($responseContent->data->roles->data) > 1);
50
51
        $this->assertEquals($data['roles_ids'][0], $responseContent->data->roles->data[0]->id);
52
53
        $this->assertEquals($data['roles_ids'][1], $responseContent->data->roles->data[1]->id);
54
    }
55
56
}
57