|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\Authentication\UI\API\Tests\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use App\Port\Tests\PHPUnit\Abstracts\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class LogoutEndpointTest. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class LogoutTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
private $endpoint = '/logout'; |
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
public function testLogout_() |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
// send the HTTP request |
|
20
|
|
|
$response = $this->apiCall($this->endpoint, 'post'); |
|
21
|
|
|
|
|
22
|
|
|
// assert response status is correct |
|
23
|
|
|
$this->assertEquals($response->getStatusCode(), '202'); |
|
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 testLogoutWithGetRequest() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
// send the HTTP request |
|
34
|
|
|
$response = $this->apiCall($this->endpoint, 'get'); |
|
35
|
|
|
|
|
36
|
|
|
// assert response status is correct |
|
37
|
|
|
$this->assertEquals($response->getStatusCode(), '405'); |
|
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 testLogoutWithoutToken() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
// send the HTTP request |
|
48
|
|
|
$response = $this->apiCall($this->endpoint, 'post', [], false); |
|
49
|
|
|
|
|
50
|
|
|
// assert response status is correct |
|
51
|
|
|
$this->assertEquals($response->getStatusCode(), '401'); |
|
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.