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

AssignUserToRoleTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAssignUserToRole_() 0 19 1
A testAssignUserToManyRoles_() 0 21 1
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
use Vinkla\Hashids\Facades\Hashids;
8
9
/**
10
 * Class AssignUserToRoleTest.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
class AssignUserToRoleTest extends TestCase
15
{
16
17
    private $endpoint = '/roles/assign';
18
19
    public function testAssignUserToRole_()
20
    {
21
        $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...
22
23
        $randomUser = factory(User::class)->create();
24
25
        $data = [
26
            'name'    => 'admin',
27
            'user_id' => $randomUser->id,
28
        ];
29
30
        // send the HTTP request
31
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
32
33
        // assert response status is correct
34
        $this->assertEquals($response->getStatusCode(), '200');
35
36
//        $this->assertEquals($data['user_id'], Hashids::decode($responseObject->data->id));
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
    }
38
39
40
    public function testAssignUserToManyRoles_()
41
    {
42
        $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...
43
44
        $randomUser = factory(User::class)->create();
45
46
        $data = [
47
            'name'    => ['admin', 'client'],
48
            'user_id' => $randomUser->id,
49
        ];
50
51
        // send the HTTP request
52
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
53
54
        // assert response status is correct
55
        $this->assertEquals($response->getStatusCode(), '200');
56
57
        $responseObject = $this->getResponseObject($response);
58
59
        $this->assertTrue(count($responseObject->data->roles->data) > 1);
60
    }
61
62
}
63