|
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(); |
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
public function testAssignUserToManyRoles_() |
|
41
|
|
|
{ |
|
42
|
|
|
$admin = $this->getLoggedInTestingAdmin(); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.