1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\User\UI\API\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use App\Containers\User\Tests\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class UpdateUserTest. |
9
|
|
|
* |
10
|
|
|
* @author Mahmoud Zalt <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class UpdateUserTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected $endpoint = 'put@users'; |
16
|
|
|
|
17
|
|
|
protected $access = [ |
18
|
|
|
'roles' => '', |
19
|
|
|
'permissions' => 'update-users', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
View Code Duplication |
public function testUpdateExistingUser_() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$user = $this->getTestingUser(); |
25
|
|
|
|
26
|
|
|
$data = [ |
27
|
|
|
'name' => 'Updated Name', |
28
|
|
|
'password' => 'updated#Password', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
// send the HTTP request |
32
|
|
|
$response = $this->makeCall($data); |
33
|
|
|
|
34
|
|
|
// assert response status is correct |
35
|
|
|
$this->assertEquals('200', $response->getStatusCode()); |
36
|
|
|
|
37
|
|
|
// assert returned user is the updated one |
38
|
|
|
$this->assertResponseContainKeyValue([ |
39
|
|
|
'email' => $user->email, |
40
|
|
|
'name' => $data['name'], |
41
|
|
|
], $response); |
42
|
|
|
|
43
|
|
|
// assert data was updated in the database |
44
|
|
|
$this->seeInDatabase('users', ['name' => $data['name']]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testUpdateExistingUserWithoutData_() |
48
|
|
|
{ |
49
|
|
|
$data = []; |
50
|
|
|
|
51
|
|
|
// send the HTTP request |
52
|
|
|
$response = $this->makeCall($data); |
53
|
|
|
|
54
|
|
|
// assert response status is correct |
55
|
|
|
$this->assertEquals('417', $response->getStatusCode()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
View Code Duplication |
public function testUpdateExistingUserWithEmptyValues() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$data = []; // empty data |
62
|
|
|
|
63
|
|
|
// send the HTTP request |
64
|
|
|
$response = $this->makeCall($data); |
65
|
|
|
|
66
|
|
|
// assert response status is correct |
67
|
|
|
$this->assertEquals('417', $response->getStatusCode()); |
68
|
|
|
|
69
|
|
|
// assert message is correct |
70
|
|
|
$this->assertResponseContainKeyValue([ |
71
|
|
|
'message' => 'Inputs are empty.', |
72
|
|
|
], $response); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.