1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Silex\WebTestCase; |
6
|
|
|
use JsonSchema\Validator; |
7
|
|
|
|
8
|
|
|
class UserTest extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
use AbstractAppTest; |
11
|
|
|
|
12
|
|
View Code Duplication |
public function testGetUser(){ |
|
|
|
|
13
|
|
|
$schema = __DIR__.'/../../../../api/schemas/userInfo.json'; |
14
|
|
|
|
15
|
|
|
$client = $this->createClient(); |
16
|
|
|
$client = $this->logIn($client); |
17
|
|
|
|
18
|
|
|
$crawler = $client->request('GET', '/api/v1/user/1'); |
|
|
|
|
19
|
|
|
$response = $client->getResponse(); |
|
|
|
|
20
|
|
|
|
21
|
|
|
//print_r($response); |
22
|
|
|
$data = $client->getResponse()->getContent(); |
23
|
|
|
$validator = $this->askValidation($data, $schema); |
24
|
|
|
|
25
|
|
|
$assert = $this->evalValidation($validator); |
26
|
|
|
$this->assertTrue($assert); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testPostBadge(){ |
30
|
|
|
$client = $this->createClient(); |
31
|
|
|
$client = $this->logIn($client); |
32
|
|
|
|
33
|
|
|
$badge_id=5; |
34
|
|
|
|
35
|
|
|
$badge = '{ |
36
|
|
|
"id": '.$badge_id.' |
37
|
|
|
}'; |
38
|
|
|
|
39
|
|
|
$client->request( |
40
|
|
|
'POST', |
41
|
|
|
'/api/v1/user/1/badge', |
42
|
|
|
[], |
43
|
|
|
[], |
44
|
|
|
['CONTENT_TYPE' => 'application/json'], |
45
|
|
|
$badge); |
46
|
|
|
|
47
|
|
|
$response = $client->getResponse(); |
48
|
|
|
$this->assertEquals(200,$response->getStatusCode()); |
49
|
|
|
return $badge_id; |
50
|
|
|
} |
51
|
|
|
public function testGetBadge(){ |
52
|
|
|
$schema = __DIR__.'/../../../../api/schemas/badgeUser.json'; |
53
|
|
|
|
54
|
|
|
$badge_id = $this->testPostBadge(); |
55
|
|
|
$client = $this->createClient(); |
56
|
|
|
$client = $this->logIn($client); |
57
|
|
|
|
58
|
|
|
$crawler = $client->request('GET', '/api/v1/user/1/badge/'.$badge_id); |
|
|
|
|
59
|
|
|
$response = $client->getResponse(); |
|
|
|
|
60
|
|
|
|
61
|
|
|
//print_r($response); |
62
|
|
|
$data = $client->getResponse()->getContent(); |
63
|
|
|
|
64
|
|
|
print_r($data); |
65
|
|
|
$validator = $this->askValidation($data, $schema); |
66
|
|
|
|
67
|
|
|
$assert = $this->evalValidation($validator); |
68
|
|
|
$this->assertTrue($assert); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function testDeleteBadge(){ |
|
|
|
|
72
|
|
|
$client = $this->createClient(); |
73
|
|
|
$client = $this->logIn($client); |
74
|
|
|
|
75
|
|
|
$badge_id = $this->testPostBadge(); |
76
|
|
|
|
77
|
|
|
$client->request( |
78
|
|
|
'DELETE', |
79
|
|
|
'/api/v1/user/1/badge/'.$badge_id.'', |
80
|
|
|
[], |
81
|
|
|
[], |
82
|
|
|
[], |
83
|
|
|
''); |
84
|
|
|
|
85
|
|
|
$response = $client->getResponse(); |
86
|
|
|
$this->assertEquals(204,$response->getStatusCode()); |
87
|
|
|
return $badge_id; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
public function testPostBadgeCompleted(){ |
|
|
|
|
91
|
|
|
$client = $this->createClient(); |
92
|
|
|
$client = $this->logIn($client); |
93
|
|
|
|
94
|
|
|
$badge_id = $this->testPostBadge(); |
95
|
|
|
|
96
|
|
|
$client->request( |
97
|
|
|
'PATCH', |
98
|
|
|
'/api/v1/user/1/badge/'.$badge_id.'/completed', |
99
|
|
|
[], |
100
|
|
|
[], |
101
|
|
|
[], |
102
|
|
|
''); |
103
|
|
|
|
104
|
|
|
$response = $client->getResponse(); |
105
|
|
|
$this->assertEquals(204,$response->getStatusCode()); |
106
|
|
|
return $badge_id; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
View Code Duplication |
public function testGetUserTicket(){ |
|
|
|
|
110
|
|
|
$schema = __DIR__.'/../../../../api/schemas/ticketList.json'; |
111
|
|
|
|
112
|
|
|
$client = $this->createClient(); |
113
|
|
|
$client = $this->logIn($client); |
114
|
|
|
|
115
|
|
|
$crawler = $client->request('GET', '/api/v1/user/1/ticket'); |
|
|
|
|
116
|
|
|
$response = $client->getResponse(); |
|
|
|
|
117
|
|
|
|
118
|
|
|
//print_r($response); |
119
|
|
|
$data = $client->getResponse()->getContent(); |
120
|
|
|
$validator = $this->askValidation($data, $schema); |
121
|
|
|
|
122
|
|
|
$assert = $this->evalValidation($validator); |
123
|
|
|
$this->assertTrue($assert); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.