Completed
Push — master ( 6e2cac...67d760 )
by Mahmoud
05:43
created

AssignUserToRoleTest::testAssignUserToRole_()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\Order\UI\API\Tests\Functional;
4
5
use App\Containers\User\Models\User;
6
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
7
8
/**
9
 * Class AssignUserToRoleTest.
10
 *
11
 * @author  Mahmoud Zalt <[email protected]>
12
 */
13
class AssignUserToRoleTest extends TestCase
14
{
15
16
    private $endpoint = '/roles/assign';
17
18
    public function testAssignUserToRole_()
19
    {
20
        $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...
21
22
        $randomUser = factory(User::class)->create();
23
24
        $data = [
25
            'roles_names' => 'admin',
26
            'user_id'     => $randomUser->getHashedKey(),
27
        ];
28
29
        // send the HTTP request
30
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
31
32
        // assert response status is correct
33
        $this->assertEquals($response->getStatusCode(), '200');
34
35
        $responseObject = $this->getResponseObject($response);
36
37
        $this->assertEquals($data['user_id'], $responseObject->data->id);
38
39
        $this->assertEquals($data['roles_names'], $responseObject->data->roles->data[0]->name);
40
    }
41
42
43
    public function testAssignUserToManyRoles_()
44
    {
45
        $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...
46
47
        $randomUser = factory(User::class)->create();
48
49
        $data = [
50
            'roles_names' => ['admin', 'client'],
51
            'user_id'     => $randomUser->getHashedKey(),
52
        ];
53
54
        // send the HTTP request
55
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
56
57
        // assert response status is correct
58
        $this->assertEquals($response->getStatusCode(), '200');
59
60
        $responseObject = $this->getResponseObject($response);
61
62
        $this->assertTrue(count($responseObject->data->roles->data) > 1);
63
64
        $this->assertEquals($data['roles_names'][0], $responseObject->data->roles->data[0]->name);
65
66
        $this->assertEquals($data['roles_names'][1], $responseObject->data->roles->data[1]->name);
67
    }
68
69
}
70