This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace FlexyProject\GitHub\Tests\Receiver; |
||
3 | |||
4 | use FlexyProject\GitHub\{ |
||
5 | Client, Receiver\Gists, Tests\AbstractClientTest |
||
6 | }; |
||
7 | |||
8 | /** |
||
9 | * Class GistsTest |
||
10 | * |
||
11 | * @package FlexyProject\GitHub\Tests |
||
12 | */ |
||
13 | class GistsTest extends AbstractClientTest |
||
14 | { |
||
15 | /** Public test gist ID */ |
||
16 | const PUBLIC_GIST = '76e253825bb3c6c084cf31f92997eb72'; |
||
17 | |||
18 | /** @var Gists */ |
||
19 | protected $gists; |
||
20 | |||
21 | /** @var Gists\Comments */ |
||
22 | protected $comments; |
||
23 | |||
24 | /** |
||
25 | * GistsTest constructor. |
||
26 | * |
||
27 | * @param null $name |
||
28 | * @param array $data |
||
29 | * @param string $dataName |
||
30 | */ |
||
31 | public function __construct($name = null, array $data = [], $dataName = '') |
||
32 | { |
||
33 | parent::__construct($name, $data, $dataName); |
||
34 | |||
35 | // Gists |
||
36 | $this->gists = $this->client->getReceiver(Client::GISTS); |
||
37 | |||
38 | // Comments |
||
39 | $this->comments = $this->gists->getReceiver(Gists::COMMENTS); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Test instance of Gists's class |
||
44 | */ |
||
45 | public function testGists() |
||
46 | { |
||
47 | $this->assertInstanceOf(Gists::class, $this->gists); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Test instance of Comments's class |
||
52 | */ |
||
53 | public function testComments() |
||
54 | { |
||
55 | $this->assertInstanceOf(Gists\Comments::class, $this->comments); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Test list gists of current users |
||
60 | */ |
||
61 | View Code Duplication | public function testListGists() |
|
0 ignored issues
–
show
|
|||
62 | { |
||
63 | $gists = $this->gists->listGists(); |
||
64 | if (!empty($gists)) { |
||
65 | $gist = array_pop($gists); |
||
66 | |||
67 | $this->assertArrayHasKey('url', $gist); |
||
68 | $this->assertArrayHasKey('files', $gist); |
||
69 | $this->assertArrayHasKey('comments', $gist); |
||
70 | $this->assertArrayHasKey('created_at', $gist); |
||
71 | $this->assertArrayHasKey('updated_at', $gist); |
||
72 | $this->assertArrayHasKey('user', $gist); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Test list public gists |
||
78 | */ |
||
79 | View Code Duplication | public function testPublicListGists() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
80 | { |
||
81 | $gists = $this->gists->listPublicGists(); |
||
82 | if (!empty($gists)) { |
||
83 | $gist = array_pop($gists); |
||
84 | |||
85 | $this->assertArrayHasKey('url', $gist); |
||
86 | $this->assertArrayHasKey('files', $gist); |
||
87 | $this->assertArrayHasKey('comments', $gist); |
||
88 | $this->assertArrayHasKey('created_at', $gist); |
||
89 | $this->assertArrayHasKey('updated_at', $gist); |
||
90 | $this->assertArrayHasKey('user', $gist); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Test list user's starred gists |
||
96 | */ |
||
97 | View Code Duplication | public function testListUsersStarredGists() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
98 | { |
||
99 | $gists = $this->gists->listUsersStarredGists(); |
||
100 | if (!empty($gists)) { |
||
101 | $gist = array_pop($gists); |
||
102 | |||
103 | $this->assertArrayHasKey('url', $gist); |
||
104 | $this->assertArrayHasKey('files', $gist); |
||
105 | $this->assertArrayHasKey('comments', $gist); |
||
106 | $this->assertArrayHasKey('created_at', $gist); |
||
107 | $this->assertArrayHasKey('updated_at', $gist); |
||
108 | $this->assertArrayHasKey('user', $gist); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Test creating a new gist |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | public function testCreateGist(): string |
||
118 | { |
||
119 | $gist = $this->gists->createGist([ |
||
120 | md5('phpunit-testing') . '.txt' => [ |
||
121 | 'content' => 'String file contents' |
||
122 | ] |
||
123 | ], 'the description for this gist'); |
||
124 | |||
125 | $this->assertArrayHasKey('url', $gist); |
||
126 | $this->assertArrayHasKey('files', $gist); |
||
127 | $this->assertArrayHasKey('comments', $gist); |
||
128 | $this->assertArrayHasKey('created_at', $gist); |
||
129 | $this->assertArrayHasKey('updated_at', $gist); |
||
130 | $this->assertArrayHasKey('user', $gist); |
||
131 | |||
132 | return $gist['id']; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Test getting gist by ID |
||
137 | * |
||
138 | * @depends testCreateGist |
||
139 | * |
||
140 | * @param string $gistId |
||
141 | */ |
||
142 | public function testGetGistById(string $gistId) |
||
143 | { |
||
144 | $gist = $this->gists->getGist($gistId); |
||
145 | |||
146 | $this->assertArrayHasKey('url', $gist); |
||
147 | $this->assertArrayHasKey('files', $gist); |
||
148 | $this->assertArrayHasKey('comments', $gist); |
||
149 | $this->assertArrayHasKey('created_at', $gist); |
||
150 | $this->assertArrayHasKey('updated_at', $gist); |
||
151 | $this->assertArrayHasKey('user', $gist); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Test updating an existing gist |
||
156 | * |
||
157 | * @depends testCreateGist |
||
158 | * |
||
159 | * @param string $gistId |
||
160 | */ |
||
161 | public function testUpdateGist(string $gistId) |
||
162 | { |
||
163 | $gist = $this->gists->editGist($gistId, 'the description UPDATED for this gist', [ |
||
164 | md5('phpunit-testing') . '.txt' => [ |
||
165 | 'content' => 'String file contents' |
||
166 | ] |
||
167 | ], 'content', 'renamed-file.name'); |
||
168 | |||
169 | $this->assertEquals('the description UPDATED for this gist', $gist['description']); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * Test list commits of a gist |
||
174 | * |
||
175 | * @depends testCreateGist |
||
176 | * |
||
177 | * @param string $gistId |
||
178 | */ |
||
179 | View Code Duplication | public function testListGistsCommit(string $gistId) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
180 | { |
||
181 | $gists = $this->gists->listGistsCommits($gistId); |
||
182 | $gist = array_pop($gists); |
||
183 | |||
184 | $this->assertArrayHasKey('user', $gist); |
||
185 | $this->assertArrayHasKey('version', $gist); |
||
186 | $this->assertArrayHasKey('committed_at', $gist); |
||
187 | $this->assertArrayHasKey('change_status', $gist); |
||
188 | $this->assertArrayHasKey('url', $gist); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Test starring a gist |
||
193 | * |
||
194 | * @depends testCreateGist |
||
195 | * |
||
196 | * @param string $gistId |
||
197 | */ |
||
198 | public function testStarGist(string $gistId) |
||
199 | { |
||
200 | $this->assertTrue($this->gists->starGist($gistId)); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Test gist is starred |
||
205 | * |
||
206 | * @depends testCreateGist |
||
207 | * |
||
208 | * @param string $gistId |
||
209 | */ |
||
210 | public function testGistIsStarred(string $gistId) |
||
211 | { |
||
212 | $this->assertTrue($this->gists->checkGistIsStarred($gistId)); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Test unstar a gist |
||
217 | * |
||
218 | * @depends testCreateGist |
||
219 | * |
||
220 | * @param string $gistId |
||
221 | */ |
||
222 | public function testUnStarGist(string $gistId) |
||
223 | { |
||
224 | $this->assertTrue($this->gists->unStarGist($gistId)); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * Test fork a public gist |
||
229 | */ |
||
230 | public function testForkGist() |
||
231 | { |
||
232 | $gist = $this->gists->forkGist(self::PUBLIC_GIST); |
||
233 | |||
234 | $this->assertArrayHasKey('forks_url', $gist); |
||
235 | |||
236 | return $gist['id']; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Test list forks of a specific gist |
||
241 | */ |
||
242 | public function testListGistForks() |
||
243 | { |
||
244 | $gists = $this->gists->listGistForks(self::PUBLIC_GIST); |
||
245 | $gist = array_pop($gists); |
||
246 | |||
247 | $this->assertArrayHasKey('url', $gist); |
||
248 | $this->assertArrayHasKey('id', $gist); |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Test deleting a forked gist |
||
253 | * |
||
254 | * @depends testForkGist |
||
255 | * |
||
256 | * @param string $gistId |
||
257 | */ |
||
258 | public function testDeleteForkedGist(string $gistId) |
||
259 | { |
||
260 | $this->assertTrue($this->gists->deleteGist($gistId)); |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * Test create a new comment in specific gist |
||
265 | * |
||
266 | * @depends testCreateGist |
||
267 | * |
||
268 | * @param string $gistId |
||
269 | */ |
||
270 | public function testCreateComment(string $gistId) |
||
271 | { |
||
272 | $response = $this->comments->createComment($gistId, 'Just commenting for the sake of commenting'); |
||
273 | |||
274 | $this->assertEquals('Just commenting for the sake of commenting', $response['body']); |
||
275 | |||
276 | return $response['id']; |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * Test listing all comments for specific gist |
||
281 | * |
||
282 | * @depends testCreateGist |
||
283 | * |
||
284 | * @param string $gistId |
||
285 | */ |
||
286 | public function testListComments(string $gistId) |
||
287 | { |
||
288 | $comments = $this->comments->listComments($gistId); |
||
289 | $comment = array_pop($comments); |
||
290 | |||
291 | $this->assertArrayHasKey('id', $comment); |
||
292 | $this->assertArrayHasKey('url', $comment); |
||
293 | $this->assertArrayHasKey('body', $comment); |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * Test getting a single comment |
||
298 | * |
||
299 | * @depends testCreateGist |
||
300 | * @depends testCreateComment |
||
301 | * |
||
302 | * @param string $gistId |
||
303 | * @param string $commentId |
||
304 | */ |
||
305 | public function testGetSingleComment(string $gistId, string $commentId) |
||
306 | { |
||
307 | $response = $this->comments->getSingleComment($gistId, $commentId); |
||
308 | |||
309 | $this->assertEquals('Just commenting for the sake of commenting', $response['body']); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Test editing a gist's comment |
||
314 | * |
||
315 | * @depends testCreateGist |
||
316 | * @depends testCreateComment |
||
317 | * |
||
318 | * @param string $gistId |
||
319 | * @param string $commentId |
||
320 | */ |
||
321 | public function testEditComment(string $gistId, string $commentId) |
||
322 | { |
||
323 | $response = $this->comments->editComment($gistId, $commentId, 'Just editing this comment!'); |
||
324 | |||
325 | $this->assertEquals('Just editing this comment!', $response['body']); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * Test deleting a comment |
||
330 | * |
||
331 | * @depends testCreateGist |
||
332 | * @depends testCreateComment |
||
333 | * |
||
334 | * @param string $gistId |
||
335 | * @param string $commentId |
||
336 | */ |
||
337 | public function testDeleteComment(string $gistId, string $commentId) |
||
338 | { |
||
339 | $this->assertTrue($this->comments->deleteComment($gistId, $commentId)); |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * Test deleting an existing gist |
||
344 | * |
||
345 | * @depends testCreateGist |
||
346 | * |
||
347 | * @param string $gistId |
||
348 | */ |
||
349 | public function testDeleteGist(string $gistId) |
||
350 | { |
||
351 | $this->assertTrue($this->gists->deleteGist($gistId)); |
||
352 | } |
||
353 | |||
354 | } |
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.