|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\Authentication\UI\API\Tests\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\Authentication\Tests\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class UserLogoutTest. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class UserLogoutTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
protected $endpoint = 'post@logout'; |
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
public function testUserLogout_() |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
// send the HTTP request |
|
20
|
|
|
$response = $this->makeCall(); |
|
21
|
|
|
|
|
22
|
|
|
// assert response status is correct |
|
23
|
|
|
$this->assertEquals('202', $response->getStatusCode()); |
|
24
|
|
|
|
|
25
|
|
|
// assert message is correct |
|
26
|
|
|
$this->assertResponseContainKeyValue([ |
|
27
|
|
|
'message' => 'User Logged Out Successfully.', |
|
28
|
|
|
], $response); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
View Code Duplication |
public function testUserLogoutWithGetRequest() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
// send the HTTP request |
|
34
|
|
|
$response = $this->endpoint('get@logout')->makeCall(); |
|
35
|
|
|
|
|
36
|
|
|
// assert response status is correct |
|
37
|
|
|
$this->assertEquals('405', $response->getStatusCode()); |
|
38
|
|
|
|
|
39
|
|
|
// assert message is correct |
|
40
|
|
|
$this->assertResponseContainKeyValue([ |
|
41
|
|
|
'message' => '405 Method Not Allowed', |
|
42
|
|
|
], $response); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
public function testUserLogoutWithoutToken() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
// send the HTTP request |
|
48
|
|
|
$response = $this->auth(false)->makeCall(); |
|
49
|
|
|
|
|
50
|
|
|
// assert response status is correct |
|
51
|
|
|
$this->assertEquals('401', $response->getStatusCode()); |
|
52
|
|
|
|
|
53
|
|
|
// assert message is correct |
|
54
|
|
|
$this->assertResponseContainKeyValue([ |
|
55
|
|
|
'message' => 'Failed to authenticate because of bad credentials or an invalid authorization header.', |
|
56
|
|
|
], $response); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
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.