1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\User\UI\API\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use App\Containers\User\Tests\ApiTestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class FindUsersTest. |
9
|
|
|
* |
10
|
|
|
* @group user |
11
|
|
|
* @group api |
12
|
|
|
* |
13
|
|
|
* @author Mahmoud Zalt <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class FindUserTest extends ApiTestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
protected $endpoint = '[email protected]/users/{id}'; |
19
|
|
|
|
20
|
|
|
protected $access = [ |
21
|
|
|
'roles' => '', |
22
|
|
|
'permissions' => 'search-users', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
*/ |
28
|
|
|
public function testFindUser_() |
29
|
|
|
{ |
30
|
|
|
$admin = $this->getTestingUser(); |
31
|
|
|
|
32
|
|
|
// send the HTTP request |
33
|
|
|
$response = $this->injectId($admin->id)->makeCall(); |
34
|
|
|
|
35
|
|
|
// assert response status is correct |
36
|
|
|
$response->assertStatus(200); |
37
|
|
|
|
38
|
|
|
$responseContent = $this->getResponseContentObject(); |
39
|
|
|
|
40
|
|
|
$this->assertEquals($admin->name, $responseContent->data->name); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
*/ |
46
|
|
|
public function testFindFilteredUserResponse_() |
47
|
|
|
{ |
48
|
|
|
$admin = $this->getTestingUser(); |
49
|
|
|
|
50
|
|
|
// send the HTTP request |
51
|
|
|
$response = $this->injectId($admin->id)->endpoint($this->endpoint . '?filter=email;name')->makeCall(); |
52
|
|
|
|
53
|
|
|
// assert response status is correct |
54
|
|
|
$response->assertStatus(200); |
55
|
|
|
|
56
|
|
|
$responseContent = $this->getResponseContentObject(); |
|
|
|
|
57
|
|
|
|
58
|
|
|
# todo: to fix |
59
|
|
|
// $this->assertEquals($admin->name, $responseContent->data->name); |
60
|
|
|
// $this->assertEquals($admin->email, $responseContent->data->email); |
61
|
|
|
|
62
|
|
|
$this->assertNotContains('id', json_decode($response->getContent(), true)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
*/ |
68
|
|
|
public function testFindUserWithRelation_() |
69
|
|
|
{ |
70
|
|
|
$admin = $this->getTestingUser(); |
71
|
|
|
|
72
|
|
|
// send the HTTP request |
73
|
|
|
$response = $this->injectId($admin->id)->endpoint($this->endpoint . '?include=roles')->makeCall(); |
74
|
|
|
|
75
|
|
|
// assert response status is correct |
76
|
|
|
$response->assertStatus(200); |
77
|
|
|
|
78
|
|
|
$responseContent = $this->getResponseContentObject(); |
79
|
|
|
|
80
|
|
|
$this->assertEquals($admin->email, $responseContent->data->email); |
81
|
|
|
|
82
|
|
|
$this->assertNotNull($responseContent->data->roles); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.