@@ -12,44 +12,44 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class AbstractActivity |
14 | 14 | { |
15 | - /** Api trait */ |
|
16 | - use Api; |
|
15 | + /** Api trait */ |
|
16 | + use Api; |
|
17 | 17 | |
18 | - /** Properties */ |
|
19 | - protected $activity; |
|
18 | + /** Properties */ |
|
19 | + protected $activity; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor |
|
23 | - * |
|
24 | - * @param Activity $activity |
|
25 | - */ |
|
26 | - public function __construct(Activity $activity) |
|
27 | - { |
|
28 | - $this->setActivity($activity); |
|
29 | - $this->setApi($activity->getApi()); |
|
30 | - } |
|
21 | + /** |
|
22 | + * Constructor |
|
23 | + * |
|
24 | + * @param Activity $activity |
|
25 | + */ |
|
26 | + public function __construct(Activity $activity) |
|
27 | + { |
|
28 | + $this->setActivity($activity); |
|
29 | + $this->setApi($activity->getApi()); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Get activity |
|
34 | - * |
|
35 | - * @return Activity |
|
36 | - */ |
|
37 | - public function getActivity(): Activity |
|
38 | - { |
|
39 | - return $this->activity; |
|
40 | - } |
|
32 | + /** |
|
33 | + * Get activity |
|
34 | + * |
|
35 | + * @return Activity |
|
36 | + */ |
|
37 | + public function getActivity(): Activity |
|
38 | + { |
|
39 | + return $this->activity; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Set activity |
|
44 | - * |
|
45 | - * @param Activity $activity |
|
46 | - * |
|
47 | - * @return AbstractActivity |
|
48 | - */ |
|
49 | - public function setActivity(Activity $activity): AbstractActivity |
|
50 | - { |
|
51 | - $this->activity = $activity; |
|
42 | + /** |
|
43 | + * Set activity |
|
44 | + * |
|
45 | + * @param Activity $activity |
|
46 | + * |
|
47 | + * @return AbstractActivity |
|
48 | + */ |
|
49 | + public function setActivity(Activity $activity): AbstractActivity |
|
50 | + { |
|
51 | + $this->activity = $activity; |
|
52 | 52 | |
53 | - return $this; |
|
54 | - } |
|
53 | + return $this; |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -13,572 +13,572 @@ |
||
13 | 13 | abstract class AbstractApi |
14 | 14 | { |
15 | 15 | |
16 | - /** API version */ |
|
17 | - const API_VERSION = 'v3'; |
|
18 | - |
|
19 | - /** API constants */ |
|
20 | - const API_URL = 'https://api.github.com'; |
|
21 | - const API_UPLOADS = 'https://uploads.github.com'; |
|
22 | - const API_RAW_URL = 'https://raw.github.com'; |
|
23 | - const CONTENT_TYPE = 'application/json'; |
|
24 | - const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json'; |
|
25 | - const USER_AGENT = 'FlexyProject-GitHubAPI'; |
|
26 | - |
|
27 | - /** Archive constants */ |
|
28 | - const ARCHIVE_TARBALL = 'tarball'; |
|
29 | - const ARCHIVE_ZIPBALL = 'zipball'; |
|
30 | - |
|
31 | - /** Authentication constants */ |
|
32 | - const OAUTH_AUTH = 0; |
|
33 | - const OAUTH2_HEADER_AUTH = 1; |
|
34 | - const OAUTH2_PARAMETERS_AUTH = 2; |
|
35 | - |
|
36 | - /** Branch constants */ |
|
37 | - const BRANCH_MASTER = 'master'; |
|
38 | - const BRANCH_DEVELOP = 'develop'; |
|
39 | - |
|
40 | - /** Direction constants */ |
|
41 | - const DIRECTION_ASC = 'asc'; |
|
42 | - const DIRECTION_DESC = 'desc'; |
|
43 | - |
|
44 | - /** Environment constants */ |
|
45 | - const ENVIRONMENT_PRODUCTION = 'production'; |
|
46 | - const ENVIRONMENT_STAGING = 'staging'; |
|
47 | - const ENVIRONMENT_QA = 'qa'; |
|
48 | - |
|
49 | - /** Events constants */ |
|
50 | - const EVENTS_PULL = 'pull'; |
|
51 | - const EVENTS_PULL_REQUEST = 'pull_request'; |
|
52 | - const EVENTS_PUSH = 'push'; |
|
53 | - |
|
54 | - /** Filter constants */ |
|
55 | - const FILTER_ALL = 'all'; |
|
56 | - const FILTER_ASSIGNED = 'assigned'; |
|
57 | - const FILTER_CREATED = 'created'; |
|
58 | - const FILTER_MENTIONED = 'mentioned'; |
|
59 | - const FILTER_SUBSCRIBED = 'subscribed'; |
|
60 | - |
|
61 | - /** Media types constants */ |
|
62 | - const MEDIA_TYPE_JSON = 'json'; |
|
63 | - const MEDIA_TYPE_RAW = 'raw'; |
|
64 | - const MEDIA_TYPE_FULL = 'full'; |
|
65 | - const MEDIA_TYPE_TEXT = 'text'; |
|
66 | - |
|
67 | - /** Modes constants */ |
|
68 | - const MODE_MARKDOWN = 'markdown'; |
|
69 | - const MODE_GFM = 'gfm'; |
|
70 | - |
|
71 | - /** Permissions constants */ |
|
72 | - const PERMISSION_ADMIN = 'admin'; |
|
73 | - const PERMISSION_PULL = 'pull'; |
|
74 | - const PERMISSION_PUSH = 'push'; |
|
75 | - |
|
76 | - /** Sort constants */ |
|
77 | - const SORT_COMPLETENESS = 'completeness'; |
|
78 | - const SORT_CREATED = 'created'; |
|
79 | - const SORT_DUE_DATE = 'due_date'; |
|
80 | - const SORT_FULL_NAME = 'full_name'; |
|
81 | - const SORT_NEWEST = 'newest'; |
|
82 | - const SORT_OLDEST = 'oldest'; |
|
83 | - const SORT_PUSHED = 'pushed'; |
|
84 | - const SORT_STARGAZERS = 'stargazers'; |
|
85 | - const SORT_UPDATED = 'updated'; |
|
86 | - |
|
87 | - /** State constants */ |
|
88 | - const STATE_ACTIVE = 'active'; |
|
89 | - const STATE_ALL = 'all'; |
|
90 | - const STATE_CLOSED = 'closed'; |
|
91 | - const STATE_ERROR = 'error'; |
|
92 | - const STATE_FAILURE = 'failure'; |
|
93 | - const STATE_OPEN = 'open'; |
|
94 | - const STATE_PENDING = 'pending'; |
|
95 | - const STATE_SUCCESS = 'success'; |
|
96 | - |
|
97 | - /** Task constants */ |
|
98 | - const TASK_DEPLOY = 'deploy'; |
|
99 | - const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations'; |
|
100 | - |
|
101 | - /** Type constants */ |
|
102 | - const TYPE_ALL = 'all'; |
|
103 | - const TYPE_COMMENTS = 'comments'; |
|
104 | - const TYPE_GISTS = 'gists'; |
|
105 | - const TYPE_HOOKS = 'hooks'; |
|
106 | - const TYPE_ISSUES = 'issues'; |
|
107 | - const TYPE_MEMBER = 'member'; |
|
108 | - const TYPE_MILESTONES = 'milestones'; |
|
109 | - const TYPE_ORGS = 'orgs'; |
|
110 | - const TYPE_OWNER = 'owner'; |
|
111 | - const TYPE_PAGES = 'pages'; |
|
112 | - const TYPE_PUBLIC = 'public'; |
|
113 | - const TYPE_PULLS = 'pulls'; |
|
114 | - const TYPE_PRIVATE = 'private'; |
|
115 | - const TYPE_REPOS = 'repos'; |
|
116 | - const TYPE_USERS = 'users'; |
|
117 | - |
|
118 | - /** Properties */ |
|
119 | - protected $accept = self::DEFAULT_ACCEPT; |
|
120 | - protected $apiUrl = self::API_URL; |
|
121 | - protected $authentication = self::OAUTH_AUTH; |
|
122 | - protected $clientId; |
|
123 | - protected $clientSecret; |
|
124 | - protected $contentType = self::CONTENT_TYPE; |
|
125 | - protected $failure; |
|
126 | - protected $headers = []; |
|
127 | - protected $httpAuth = ['username' => '', 'password' => '']; |
|
128 | - protected $success; |
|
129 | - protected $timeout = 240; |
|
130 | - protected $token = ''; |
|
131 | - protected $request; |
|
132 | - |
|
133 | - /** |
|
134 | - * Constructor |
|
135 | - */ |
|
136 | - public function __construct() |
|
137 | - { |
|
138 | - $this->request = Request::createFromGlobals(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Get request |
|
143 | - * |
|
144 | - * @return Request |
|
145 | - */ |
|
146 | - public function getRequest(): Request |
|
147 | - { |
|
148 | - return $this->request; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Get accept |
|
153 | - * |
|
154 | - * @return mixed |
|
155 | - */ |
|
156 | - public function getAccept() |
|
157 | - { |
|
158 | - return $this->accept; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Set accept |
|
163 | - * |
|
164 | - * @param array|string $accept |
|
165 | - * |
|
166 | - * @return AbstractApi |
|
167 | - */ |
|
168 | - public function setAccept($accept): AbstractApi |
|
169 | - { |
|
170 | - $this->accept = $accept; |
|
171 | - |
|
172 | - return $this; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get authentication |
|
177 | - * |
|
178 | - * @return int |
|
179 | - */ |
|
180 | - public function getAuthentication(): int |
|
181 | - { |
|
182 | - return $this->authentication; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Set authentication |
|
187 | - * |
|
188 | - * @param int $authentication |
|
189 | - * |
|
190 | - * @return AbstractApi |
|
191 | - */ |
|
192 | - public function setAuthentication(int $authentication): AbstractApi |
|
193 | - { |
|
194 | - $this->authentication = $authentication; |
|
195 | - |
|
196 | - return $this; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Get apiUrl |
|
201 | - * |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function getApiUrl(): string |
|
205 | - { |
|
206 | - return $this->apiUrl; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Set apiUrl |
|
211 | - * |
|
212 | - * @param mixed $apiUrl |
|
213 | - * |
|
214 | - * @return AbstractApi |
|
215 | - */ |
|
216 | - public function setApiUrl($apiUrl): AbstractApi |
|
217 | - { |
|
218 | - $this->apiUrl = $apiUrl; |
|
219 | - |
|
220 | - return $this; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Get clientId |
|
225 | - * |
|
226 | - * @return null|int |
|
227 | - */ |
|
228 | - public function getClientId() |
|
229 | - { |
|
230 | - return $this->clientId; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Set clientId |
|
235 | - * |
|
236 | - * @param mixed $clientId |
|
237 | - * |
|
238 | - * @return AbstractApi |
|
239 | - */ |
|
240 | - public function setClientId($clientId): AbstractApi |
|
241 | - { |
|
242 | - $this->clientId = $clientId; |
|
243 | - |
|
244 | - return $this; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Get clientSecret |
|
249 | - * |
|
250 | - * @return null|string |
|
251 | - */ |
|
252 | - public function getClientSecret() |
|
253 | - { |
|
254 | - return $this->clientSecret; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Set clientSecret |
|
259 | - * |
|
260 | - * @param mixed $clientSecret |
|
261 | - * |
|
262 | - * @return AbstractApi |
|
263 | - */ |
|
264 | - public function setClientSecret($clientSecret): AbstractApi |
|
265 | - { |
|
266 | - $this->clientSecret = $clientSecret; |
|
267 | - |
|
268 | - return $this; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Get httpAuth |
|
273 | - * |
|
274 | - * @return array |
|
275 | - */ |
|
276 | - public function getHttpAuth(): array |
|
277 | - { |
|
278 | - return $this->httpAuth; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Set httpAuth |
|
283 | - * |
|
284 | - * @param string $username |
|
285 | - * @param string $password |
|
286 | - * |
|
287 | - * @return AbstractApi |
|
288 | - */ |
|
289 | - public function setHttpAuth(string $username, string $password = ''): AbstractApi |
|
290 | - { |
|
291 | - $this->httpAuth['username'] = $username; |
|
292 | - $this->httpAuth['password'] = $password; |
|
293 | - |
|
294 | - return $this; |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get token |
|
299 | - * |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function getToken(): string |
|
303 | - { |
|
304 | - return $this->token; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Set token |
|
309 | - * |
|
310 | - * @param string $token |
|
311 | - * @param int $authentication |
|
312 | - * |
|
313 | - * @return AbstractApi |
|
314 | - */ |
|
315 | - public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi |
|
316 | - { |
|
317 | - $this->token = $token; |
|
318 | - $this->setAuthentication($authentication); |
|
319 | - |
|
320 | - return $this; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Get timeout |
|
325 | - * |
|
326 | - * @return int |
|
327 | - */ |
|
328 | - public function getTimeout(): int |
|
329 | - { |
|
330 | - return $this->timeout; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Set timeout |
|
335 | - * |
|
336 | - * @param int $timeout |
|
337 | - * |
|
338 | - * @return AbstractApi |
|
339 | - */ |
|
340 | - public function setTimeout(int $timeout): AbstractApi |
|
341 | - { |
|
342 | - $this->timeout = $timeout; |
|
343 | - |
|
344 | - return $this; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Get contentType |
|
349 | - * |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public function getContentType(): string |
|
353 | - { |
|
354 | - return $this->contentType; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Set contentType |
|
359 | - * |
|
360 | - * @param string $contentType |
|
361 | - * |
|
362 | - * @return AbstractApi |
|
363 | - */ |
|
364 | - public function setContentType(string $contentType): AbstractApi |
|
365 | - { |
|
366 | - $this->contentType = $contentType; |
|
367 | - |
|
368 | - return $this; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get headers |
|
373 | - * |
|
374 | - * @return array |
|
375 | - */ |
|
376 | - public function getHeaders(): array |
|
377 | - { |
|
378 | - return $this->headers; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Curl request |
|
383 | - * |
|
384 | - * @param string $url |
|
385 | - * @param string $method |
|
386 | - * @param array $postFields |
|
387 | - * @param null|string $apiUrl |
|
388 | - * |
|
389 | - * @return array |
|
390 | - */ |
|
391 | - public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [], |
|
392 | - string $apiUrl = null): array |
|
393 | - { |
|
394 | - /** Building url */ |
|
395 | - if (null === $apiUrl) { |
|
396 | - $apiUrl = $this->getApiUrl(); |
|
397 | - } |
|
398 | - $url = $apiUrl . $url; |
|
399 | - |
|
400 | - /** |
|
401 | - * OAuth2 Key/Secret authentication |
|
402 | - * |
|
403 | - * @see https://developer.github.com/v3/#oauth2-keysecret |
|
404 | - */ |
|
405 | - if (null !== $this->getClientId() && null !== $this->getClientSecret()) { |
|
406 | - $url .= (strstr($url, '?') !== false ? '&' : '?'); |
|
407 | - $url .= http_build_query(['client_id' => $this->getClientId(), |
|
408 | - 'client_secret' => $this->getClientSecret() |
|
409 | - ]); |
|
410 | - } /** |
|
411 | - * Basic authentication via OAuth2 Token (sent as a parameter) |
|
412 | - * |
|
413 | - * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter |
|
414 | - */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) { |
|
415 | - $url .= http_build_query(['access_token' => $this->getToken()]); |
|
416 | - } |
|
417 | - |
|
418 | - /** Call curl */ |
|
419 | - $curl = new CurlClient(); |
|
420 | - $curl->setOption([ |
|
421 | - CURLOPT_USERAGENT => self::USER_AGENT, |
|
422 | - CURLOPT_TIMEOUT => $this->getTimeout(), |
|
423 | - CURLOPT_HEADER => false, // Use $client->getHeaders() to get full header |
|
424 | - CURLOPT_FOLLOWLOCATION => true, |
|
425 | - CURLOPT_HTTPHEADER => [ |
|
426 | - 'Accept: ' . $this->getAccept(), |
|
427 | - 'Content-Type: ' . $this->getContentType() |
|
428 | - ], |
|
429 | - CURLOPT_URL => $url |
|
430 | - ]); |
|
431 | - |
|
432 | - /** |
|
433 | - * Basic authentication via username and Password |
|
434 | - * |
|
435 | - * @see https://developer.github.com/v3/auth/#via-username-and-password |
|
436 | - */ |
|
437 | - if (!empty($this->getHttpAuth())) { |
|
438 | - if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) { |
|
439 | - $curl->setOption([ |
|
440 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
441 | - CURLOPT_USERPWD => $this->getHttpAuth()['username'] |
|
442 | - ]); |
|
443 | - } else { |
|
444 | - $curl->setOption([ |
|
445 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
446 | - CURLOPT_USERPWD => sprintf('%s:%s', $this->getHttpAuth()['username'], |
|
447 | - $this->getHttpAuth()['password']) |
|
448 | - ]); |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) { |
|
453 | - /** |
|
454 | - * Basic authentication via OAuth token |
|
455 | - * |
|
456 | - * @see https://developer.github.com/v3/auth/#via-oauth-tokens |
|
457 | - **/ |
|
458 | - if ($this->getAuthentication() === self::OAUTH_AUTH) { |
|
459 | - $curl->setOption([ |
|
460 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
461 | - CURLOPT_USERPWD => sprintf('%s:x-oauth-basic', $this->getToken()) |
|
462 | - ]); |
|
463 | - } /** |
|
464 | - * Basic authentication via OAuth2 Token (sent in a header) |
|
465 | - * |
|
466 | - * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header |
|
467 | - */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) { |
|
468 | - $curl->setOption([ |
|
469 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
470 | - CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())] |
|
471 | - ]); |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - /** Methods */ |
|
476 | - switch ($method) { |
|
477 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */ |
|
478 | - case Request::METHOD_DELETE: |
|
479 | - /** @see http://tools.ietf.org/html/rfc5789 */ |
|
480 | - case Request::METHOD_PATCH: |
|
481 | - $curl->setOption([ |
|
482 | - CURLOPT_CUSTOMREQUEST => $method, |
|
483 | - CURLOPT_POST => true, |
|
484 | - CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
485 | - ]); |
|
486 | - break; |
|
487 | - |
|
488 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */ |
|
489 | - case Request::METHOD_GET: |
|
490 | - $curl->setOption(CURLOPT_HTTPGET, true); |
|
491 | - break; |
|
492 | - |
|
493 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */ |
|
494 | - case Request::METHOD_HEAD: |
|
495 | - $curl->setOption([ |
|
496 | - CURLOPT_CUSTOMREQUEST => $method, |
|
497 | - CURLOPT_NOBODY => true |
|
498 | - ]); |
|
499 | - break; |
|
500 | - |
|
501 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */ |
|
502 | - case Request::METHOD_POST: |
|
503 | - $curl->setOption([ |
|
504 | - CURLOPT_POST => true, |
|
505 | - CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
506 | - ]); |
|
507 | - break; |
|
508 | - |
|
509 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */ |
|
510 | - case Request::METHOD_PUT: |
|
511 | - $curl->setOption([ |
|
512 | - CURLOPT_CUSTOMREQUEST => $method, |
|
513 | - CURLOPT_PUT => true, |
|
514 | - CURLOPT_HTTPHEADER => [ |
|
515 | - 'X-HTTP-Method-Override: PUT', |
|
516 | - 'Content-type: application/x-www-form-urlencoded' |
|
517 | - ] |
|
518 | - ]); |
|
519 | - break; |
|
520 | - |
|
521 | - default: |
|
522 | - break; |
|
523 | - } |
|
524 | - |
|
525 | - $curl->success(function (CurlClient $instance) { |
|
526 | - $this->headers = $instance->getHeaders(); |
|
527 | - $this->success = $instance->getResponse(); |
|
528 | - $data = json_decode($this->success, true); |
|
529 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
530 | - $this->success = $data; |
|
531 | - } |
|
532 | - }); |
|
533 | - $curl->error(function (CurlClient $instance) { |
|
534 | - $this->headers = $instance->getHeaders(); |
|
535 | - $this->failure = $instance->getResponse(); |
|
536 | - $data = json_decode($this->failure, true); |
|
537 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
538 | - $this->failure = $data; |
|
539 | - } |
|
540 | - }); |
|
541 | - $curl->perform(); |
|
542 | - |
|
543 | - return (array)($this->success ?? $this->failure); |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Return a formatted string. Modified version of sprintf using colon(:) |
|
548 | - * |
|
549 | - * @param string $string |
|
550 | - * @param array $params |
|
551 | - * |
|
552 | - * @return String |
|
553 | - * @throws Exception |
|
554 | - */ |
|
555 | - public function sprintf(string $string, ...$params): string |
|
556 | - { |
|
557 | - preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches); |
|
558 | - $matches = $matches[1]; |
|
559 | - |
|
560 | - if (count($matches)) { |
|
561 | - $tokens = []; |
|
562 | - $replaces = []; |
|
563 | - |
|
564 | - foreach ($matches as $key => $value) { |
|
565 | - if (count($params) > 1 || !is_array($params[0])) { |
|
566 | - if (!array_key_exists($key, $params)) { |
|
567 | - throw new Exception('Too few arguments, missing argument: ' . $key); |
|
568 | - } |
|
569 | - $replaces[] = $params[$key]; |
|
570 | - } else { |
|
571 | - if (!array_key_exists($value, $params[0])) { |
|
572 | - throw new Exception('Missing array argument: ' . $key); |
|
573 | - } |
|
574 | - $replaces[] = $params[0][$value]; |
|
575 | - } |
|
576 | - $tokens[] = ':' . $value; |
|
577 | - } |
|
578 | - |
|
579 | - $string = str_replace($tokens, $replaces, $string); |
|
580 | - } |
|
581 | - |
|
582 | - return $string; |
|
583 | - } |
|
16 | + /** API version */ |
|
17 | + const API_VERSION = 'v3'; |
|
18 | + |
|
19 | + /** API constants */ |
|
20 | + const API_URL = 'https://api.github.com'; |
|
21 | + const API_UPLOADS = 'https://uploads.github.com'; |
|
22 | + const API_RAW_URL = 'https://raw.github.com'; |
|
23 | + const CONTENT_TYPE = 'application/json'; |
|
24 | + const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json'; |
|
25 | + const USER_AGENT = 'FlexyProject-GitHubAPI'; |
|
26 | + |
|
27 | + /** Archive constants */ |
|
28 | + const ARCHIVE_TARBALL = 'tarball'; |
|
29 | + const ARCHIVE_ZIPBALL = 'zipball'; |
|
30 | + |
|
31 | + /** Authentication constants */ |
|
32 | + const OAUTH_AUTH = 0; |
|
33 | + const OAUTH2_HEADER_AUTH = 1; |
|
34 | + const OAUTH2_PARAMETERS_AUTH = 2; |
|
35 | + |
|
36 | + /** Branch constants */ |
|
37 | + const BRANCH_MASTER = 'master'; |
|
38 | + const BRANCH_DEVELOP = 'develop'; |
|
39 | + |
|
40 | + /** Direction constants */ |
|
41 | + const DIRECTION_ASC = 'asc'; |
|
42 | + const DIRECTION_DESC = 'desc'; |
|
43 | + |
|
44 | + /** Environment constants */ |
|
45 | + const ENVIRONMENT_PRODUCTION = 'production'; |
|
46 | + const ENVIRONMENT_STAGING = 'staging'; |
|
47 | + const ENVIRONMENT_QA = 'qa'; |
|
48 | + |
|
49 | + /** Events constants */ |
|
50 | + const EVENTS_PULL = 'pull'; |
|
51 | + const EVENTS_PULL_REQUEST = 'pull_request'; |
|
52 | + const EVENTS_PUSH = 'push'; |
|
53 | + |
|
54 | + /** Filter constants */ |
|
55 | + const FILTER_ALL = 'all'; |
|
56 | + const FILTER_ASSIGNED = 'assigned'; |
|
57 | + const FILTER_CREATED = 'created'; |
|
58 | + const FILTER_MENTIONED = 'mentioned'; |
|
59 | + const FILTER_SUBSCRIBED = 'subscribed'; |
|
60 | + |
|
61 | + /** Media types constants */ |
|
62 | + const MEDIA_TYPE_JSON = 'json'; |
|
63 | + const MEDIA_TYPE_RAW = 'raw'; |
|
64 | + const MEDIA_TYPE_FULL = 'full'; |
|
65 | + const MEDIA_TYPE_TEXT = 'text'; |
|
66 | + |
|
67 | + /** Modes constants */ |
|
68 | + const MODE_MARKDOWN = 'markdown'; |
|
69 | + const MODE_GFM = 'gfm'; |
|
70 | + |
|
71 | + /** Permissions constants */ |
|
72 | + const PERMISSION_ADMIN = 'admin'; |
|
73 | + const PERMISSION_PULL = 'pull'; |
|
74 | + const PERMISSION_PUSH = 'push'; |
|
75 | + |
|
76 | + /** Sort constants */ |
|
77 | + const SORT_COMPLETENESS = 'completeness'; |
|
78 | + const SORT_CREATED = 'created'; |
|
79 | + const SORT_DUE_DATE = 'due_date'; |
|
80 | + const SORT_FULL_NAME = 'full_name'; |
|
81 | + const SORT_NEWEST = 'newest'; |
|
82 | + const SORT_OLDEST = 'oldest'; |
|
83 | + const SORT_PUSHED = 'pushed'; |
|
84 | + const SORT_STARGAZERS = 'stargazers'; |
|
85 | + const SORT_UPDATED = 'updated'; |
|
86 | + |
|
87 | + /** State constants */ |
|
88 | + const STATE_ACTIVE = 'active'; |
|
89 | + const STATE_ALL = 'all'; |
|
90 | + const STATE_CLOSED = 'closed'; |
|
91 | + const STATE_ERROR = 'error'; |
|
92 | + const STATE_FAILURE = 'failure'; |
|
93 | + const STATE_OPEN = 'open'; |
|
94 | + const STATE_PENDING = 'pending'; |
|
95 | + const STATE_SUCCESS = 'success'; |
|
96 | + |
|
97 | + /** Task constants */ |
|
98 | + const TASK_DEPLOY = 'deploy'; |
|
99 | + const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations'; |
|
100 | + |
|
101 | + /** Type constants */ |
|
102 | + const TYPE_ALL = 'all'; |
|
103 | + const TYPE_COMMENTS = 'comments'; |
|
104 | + const TYPE_GISTS = 'gists'; |
|
105 | + const TYPE_HOOKS = 'hooks'; |
|
106 | + const TYPE_ISSUES = 'issues'; |
|
107 | + const TYPE_MEMBER = 'member'; |
|
108 | + const TYPE_MILESTONES = 'milestones'; |
|
109 | + const TYPE_ORGS = 'orgs'; |
|
110 | + const TYPE_OWNER = 'owner'; |
|
111 | + const TYPE_PAGES = 'pages'; |
|
112 | + const TYPE_PUBLIC = 'public'; |
|
113 | + const TYPE_PULLS = 'pulls'; |
|
114 | + const TYPE_PRIVATE = 'private'; |
|
115 | + const TYPE_REPOS = 'repos'; |
|
116 | + const TYPE_USERS = 'users'; |
|
117 | + |
|
118 | + /** Properties */ |
|
119 | + protected $accept = self::DEFAULT_ACCEPT; |
|
120 | + protected $apiUrl = self::API_URL; |
|
121 | + protected $authentication = self::OAUTH_AUTH; |
|
122 | + protected $clientId; |
|
123 | + protected $clientSecret; |
|
124 | + protected $contentType = self::CONTENT_TYPE; |
|
125 | + protected $failure; |
|
126 | + protected $headers = []; |
|
127 | + protected $httpAuth = ['username' => '', 'password' => '']; |
|
128 | + protected $success; |
|
129 | + protected $timeout = 240; |
|
130 | + protected $token = ''; |
|
131 | + protected $request; |
|
132 | + |
|
133 | + /** |
|
134 | + * Constructor |
|
135 | + */ |
|
136 | + public function __construct() |
|
137 | + { |
|
138 | + $this->request = Request::createFromGlobals(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Get request |
|
143 | + * |
|
144 | + * @return Request |
|
145 | + */ |
|
146 | + public function getRequest(): Request |
|
147 | + { |
|
148 | + return $this->request; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Get accept |
|
153 | + * |
|
154 | + * @return mixed |
|
155 | + */ |
|
156 | + public function getAccept() |
|
157 | + { |
|
158 | + return $this->accept; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Set accept |
|
163 | + * |
|
164 | + * @param array|string $accept |
|
165 | + * |
|
166 | + * @return AbstractApi |
|
167 | + */ |
|
168 | + public function setAccept($accept): AbstractApi |
|
169 | + { |
|
170 | + $this->accept = $accept; |
|
171 | + |
|
172 | + return $this; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get authentication |
|
177 | + * |
|
178 | + * @return int |
|
179 | + */ |
|
180 | + public function getAuthentication(): int |
|
181 | + { |
|
182 | + return $this->authentication; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Set authentication |
|
187 | + * |
|
188 | + * @param int $authentication |
|
189 | + * |
|
190 | + * @return AbstractApi |
|
191 | + */ |
|
192 | + public function setAuthentication(int $authentication): AbstractApi |
|
193 | + { |
|
194 | + $this->authentication = $authentication; |
|
195 | + |
|
196 | + return $this; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Get apiUrl |
|
201 | + * |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function getApiUrl(): string |
|
205 | + { |
|
206 | + return $this->apiUrl; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Set apiUrl |
|
211 | + * |
|
212 | + * @param mixed $apiUrl |
|
213 | + * |
|
214 | + * @return AbstractApi |
|
215 | + */ |
|
216 | + public function setApiUrl($apiUrl): AbstractApi |
|
217 | + { |
|
218 | + $this->apiUrl = $apiUrl; |
|
219 | + |
|
220 | + return $this; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get clientId |
|
225 | + * |
|
226 | + * @return null|int |
|
227 | + */ |
|
228 | + public function getClientId() |
|
229 | + { |
|
230 | + return $this->clientId; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Set clientId |
|
235 | + * |
|
236 | + * @param mixed $clientId |
|
237 | + * |
|
238 | + * @return AbstractApi |
|
239 | + */ |
|
240 | + public function setClientId($clientId): AbstractApi |
|
241 | + { |
|
242 | + $this->clientId = $clientId; |
|
243 | + |
|
244 | + return $this; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Get clientSecret |
|
249 | + * |
|
250 | + * @return null|string |
|
251 | + */ |
|
252 | + public function getClientSecret() |
|
253 | + { |
|
254 | + return $this->clientSecret; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Set clientSecret |
|
259 | + * |
|
260 | + * @param mixed $clientSecret |
|
261 | + * |
|
262 | + * @return AbstractApi |
|
263 | + */ |
|
264 | + public function setClientSecret($clientSecret): AbstractApi |
|
265 | + { |
|
266 | + $this->clientSecret = $clientSecret; |
|
267 | + |
|
268 | + return $this; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Get httpAuth |
|
273 | + * |
|
274 | + * @return array |
|
275 | + */ |
|
276 | + public function getHttpAuth(): array |
|
277 | + { |
|
278 | + return $this->httpAuth; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Set httpAuth |
|
283 | + * |
|
284 | + * @param string $username |
|
285 | + * @param string $password |
|
286 | + * |
|
287 | + * @return AbstractApi |
|
288 | + */ |
|
289 | + public function setHttpAuth(string $username, string $password = ''): AbstractApi |
|
290 | + { |
|
291 | + $this->httpAuth['username'] = $username; |
|
292 | + $this->httpAuth['password'] = $password; |
|
293 | + |
|
294 | + return $this; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get token |
|
299 | + * |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function getToken(): string |
|
303 | + { |
|
304 | + return $this->token; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Set token |
|
309 | + * |
|
310 | + * @param string $token |
|
311 | + * @param int $authentication |
|
312 | + * |
|
313 | + * @return AbstractApi |
|
314 | + */ |
|
315 | + public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi |
|
316 | + { |
|
317 | + $this->token = $token; |
|
318 | + $this->setAuthentication($authentication); |
|
319 | + |
|
320 | + return $this; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Get timeout |
|
325 | + * |
|
326 | + * @return int |
|
327 | + */ |
|
328 | + public function getTimeout(): int |
|
329 | + { |
|
330 | + return $this->timeout; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Set timeout |
|
335 | + * |
|
336 | + * @param int $timeout |
|
337 | + * |
|
338 | + * @return AbstractApi |
|
339 | + */ |
|
340 | + public function setTimeout(int $timeout): AbstractApi |
|
341 | + { |
|
342 | + $this->timeout = $timeout; |
|
343 | + |
|
344 | + return $this; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Get contentType |
|
349 | + * |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public function getContentType(): string |
|
353 | + { |
|
354 | + return $this->contentType; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Set contentType |
|
359 | + * |
|
360 | + * @param string $contentType |
|
361 | + * |
|
362 | + * @return AbstractApi |
|
363 | + */ |
|
364 | + public function setContentType(string $contentType): AbstractApi |
|
365 | + { |
|
366 | + $this->contentType = $contentType; |
|
367 | + |
|
368 | + return $this; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get headers |
|
373 | + * |
|
374 | + * @return array |
|
375 | + */ |
|
376 | + public function getHeaders(): array |
|
377 | + { |
|
378 | + return $this->headers; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Curl request |
|
383 | + * |
|
384 | + * @param string $url |
|
385 | + * @param string $method |
|
386 | + * @param array $postFields |
|
387 | + * @param null|string $apiUrl |
|
388 | + * |
|
389 | + * @return array |
|
390 | + */ |
|
391 | + public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [], |
|
392 | + string $apiUrl = null): array |
|
393 | + { |
|
394 | + /** Building url */ |
|
395 | + if (null === $apiUrl) { |
|
396 | + $apiUrl = $this->getApiUrl(); |
|
397 | + } |
|
398 | + $url = $apiUrl . $url; |
|
399 | + |
|
400 | + /** |
|
401 | + * OAuth2 Key/Secret authentication |
|
402 | + * |
|
403 | + * @see https://developer.github.com/v3/#oauth2-keysecret |
|
404 | + */ |
|
405 | + if (null !== $this->getClientId() && null !== $this->getClientSecret()) { |
|
406 | + $url .= (strstr($url, '?') !== false ? '&' : '?'); |
|
407 | + $url .= http_build_query(['client_id' => $this->getClientId(), |
|
408 | + 'client_secret' => $this->getClientSecret() |
|
409 | + ]); |
|
410 | + } /** |
|
411 | + * Basic authentication via OAuth2 Token (sent as a parameter) |
|
412 | + * |
|
413 | + * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter |
|
414 | + */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) { |
|
415 | + $url .= http_build_query(['access_token' => $this->getToken()]); |
|
416 | + } |
|
417 | + |
|
418 | + /** Call curl */ |
|
419 | + $curl = new CurlClient(); |
|
420 | + $curl->setOption([ |
|
421 | + CURLOPT_USERAGENT => self::USER_AGENT, |
|
422 | + CURLOPT_TIMEOUT => $this->getTimeout(), |
|
423 | + CURLOPT_HEADER => false, // Use $client->getHeaders() to get full header |
|
424 | + CURLOPT_FOLLOWLOCATION => true, |
|
425 | + CURLOPT_HTTPHEADER => [ |
|
426 | + 'Accept: ' . $this->getAccept(), |
|
427 | + 'Content-Type: ' . $this->getContentType() |
|
428 | + ], |
|
429 | + CURLOPT_URL => $url |
|
430 | + ]); |
|
431 | + |
|
432 | + /** |
|
433 | + * Basic authentication via username and Password |
|
434 | + * |
|
435 | + * @see https://developer.github.com/v3/auth/#via-username-and-password |
|
436 | + */ |
|
437 | + if (!empty($this->getHttpAuth())) { |
|
438 | + if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) { |
|
439 | + $curl->setOption([ |
|
440 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
441 | + CURLOPT_USERPWD => $this->getHttpAuth()['username'] |
|
442 | + ]); |
|
443 | + } else { |
|
444 | + $curl->setOption([ |
|
445 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
446 | + CURLOPT_USERPWD => sprintf('%s:%s', $this->getHttpAuth()['username'], |
|
447 | + $this->getHttpAuth()['password']) |
|
448 | + ]); |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) { |
|
453 | + /** |
|
454 | + * Basic authentication via OAuth token |
|
455 | + * |
|
456 | + * @see https://developer.github.com/v3/auth/#via-oauth-tokens |
|
457 | + **/ |
|
458 | + if ($this->getAuthentication() === self::OAUTH_AUTH) { |
|
459 | + $curl->setOption([ |
|
460 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
461 | + CURLOPT_USERPWD => sprintf('%s:x-oauth-basic', $this->getToken()) |
|
462 | + ]); |
|
463 | + } /** |
|
464 | + * Basic authentication via OAuth2 Token (sent in a header) |
|
465 | + * |
|
466 | + * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header |
|
467 | + */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) { |
|
468 | + $curl->setOption([ |
|
469 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
470 | + CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())] |
|
471 | + ]); |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + /** Methods */ |
|
476 | + switch ($method) { |
|
477 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */ |
|
478 | + case Request::METHOD_DELETE: |
|
479 | + /** @see http://tools.ietf.org/html/rfc5789 */ |
|
480 | + case Request::METHOD_PATCH: |
|
481 | + $curl->setOption([ |
|
482 | + CURLOPT_CUSTOMREQUEST => $method, |
|
483 | + CURLOPT_POST => true, |
|
484 | + CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
485 | + ]); |
|
486 | + break; |
|
487 | + |
|
488 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */ |
|
489 | + case Request::METHOD_GET: |
|
490 | + $curl->setOption(CURLOPT_HTTPGET, true); |
|
491 | + break; |
|
492 | + |
|
493 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */ |
|
494 | + case Request::METHOD_HEAD: |
|
495 | + $curl->setOption([ |
|
496 | + CURLOPT_CUSTOMREQUEST => $method, |
|
497 | + CURLOPT_NOBODY => true |
|
498 | + ]); |
|
499 | + break; |
|
500 | + |
|
501 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */ |
|
502 | + case Request::METHOD_POST: |
|
503 | + $curl->setOption([ |
|
504 | + CURLOPT_POST => true, |
|
505 | + CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
506 | + ]); |
|
507 | + break; |
|
508 | + |
|
509 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */ |
|
510 | + case Request::METHOD_PUT: |
|
511 | + $curl->setOption([ |
|
512 | + CURLOPT_CUSTOMREQUEST => $method, |
|
513 | + CURLOPT_PUT => true, |
|
514 | + CURLOPT_HTTPHEADER => [ |
|
515 | + 'X-HTTP-Method-Override: PUT', |
|
516 | + 'Content-type: application/x-www-form-urlencoded' |
|
517 | + ] |
|
518 | + ]); |
|
519 | + break; |
|
520 | + |
|
521 | + default: |
|
522 | + break; |
|
523 | + } |
|
524 | + |
|
525 | + $curl->success(function (CurlClient $instance) { |
|
526 | + $this->headers = $instance->getHeaders(); |
|
527 | + $this->success = $instance->getResponse(); |
|
528 | + $data = json_decode($this->success, true); |
|
529 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
530 | + $this->success = $data; |
|
531 | + } |
|
532 | + }); |
|
533 | + $curl->error(function (CurlClient $instance) { |
|
534 | + $this->headers = $instance->getHeaders(); |
|
535 | + $this->failure = $instance->getResponse(); |
|
536 | + $data = json_decode($this->failure, true); |
|
537 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
538 | + $this->failure = $data; |
|
539 | + } |
|
540 | + }); |
|
541 | + $curl->perform(); |
|
542 | + |
|
543 | + return (array)($this->success ?? $this->failure); |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Return a formatted string. Modified version of sprintf using colon(:) |
|
548 | + * |
|
549 | + * @param string $string |
|
550 | + * @param array $params |
|
551 | + * |
|
552 | + * @return String |
|
553 | + * @throws Exception |
|
554 | + */ |
|
555 | + public function sprintf(string $string, ...$params): string |
|
556 | + { |
|
557 | + preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches); |
|
558 | + $matches = $matches[1]; |
|
559 | + |
|
560 | + if (count($matches)) { |
|
561 | + $tokens = []; |
|
562 | + $replaces = []; |
|
563 | + |
|
564 | + foreach ($matches as $key => $value) { |
|
565 | + if (count($params) > 1 || !is_array($params[0])) { |
|
566 | + if (!array_key_exists($key, $params)) { |
|
567 | + throw new Exception('Too few arguments, missing argument: ' . $key); |
|
568 | + } |
|
569 | + $replaces[] = $params[$key]; |
|
570 | + } else { |
|
571 | + if (!array_key_exists($value, $params[0])) { |
|
572 | + throw new Exception('Missing array argument: ' . $key); |
|
573 | + } |
|
574 | + $replaces[] = $params[0][$value]; |
|
575 | + } |
|
576 | + $tokens[] = ':' . $value; |
|
577 | + } |
|
578 | + |
|
579 | + $string = str_replace($tokens, $replaces, $string); |
|
580 | + } |
|
581 | + |
|
582 | + return $string; |
|
583 | + } |
|
584 | 584 | } |
585 | 585 | \ No newline at end of file |
@@ -11,19 +11,19 @@ |
||
11 | 11 | */ |
12 | 12 | class WebHookTest extends AbstractWebHookTest |
13 | 13 | { |
14 | - /** |
|
15 | - * Test instance of WebHook's class |
|
16 | - */ |
|
17 | - public function testWebHook() |
|
18 | - { |
|
19 | - $this->assertInstanceOf(WebHook::class, $this->webHook); |
|
20 | - } |
|
14 | + /** |
|
15 | + * Test instance of WebHook's class |
|
16 | + */ |
|
17 | + public function testWebHook() |
|
18 | + { |
|
19 | + $this->assertInstanceOf(WebHook::class, $this->webHook); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Test instance of Payload's class |
|
24 | - */ |
|
25 | - public function testPayload() |
|
26 | - { |
|
27 | - $this->assertInstanceOf(Payload::class, $this->payload); |
|
28 | - } |
|
22 | + /** |
|
23 | + * Test instance of Payload's class |
|
24 | + */ |
|
25 | + public function testPayload() |
|
26 | + { |
|
27 | + $this->assertInstanceOf(Payload::class, $this->payload); |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -12,320 +12,320 @@ |
||
12 | 12 | */ |
13 | 13 | class ActivityTest extends AbstractClientTest |
14 | 14 | { |
15 | - /** @var Activity\Events */ |
|
16 | - protected $events; |
|
17 | - |
|
18 | - /** @var Activity\Feeds */ |
|
19 | - protected $feeds; |
|
20 | - |
|
21 | - /** @var Activity\Notifications */ |
|
22 | - protected $notifications; |
|
23 | - |
|
24 | - /** @var Activity\Starring */ |
|
25 | - protected $starring; |
|
26 | - |
|
27 | - /** @var Activity\Watching */ |
|
28 | - protected $watching; |
|
29 | - |
|
30 | - /** |
|
31 | - * ActivityTest constructor. |
|
32 | - * |
|
33 | - * @param null $name |
|
34 | - * @param array $data |
|
35 | - * @param string $dataName |
|
36 | - */ |
|
37 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
38 | - { |
|
39 | - parent::__construct($name, $data, $dataName); |
|
40 | - |
|
41 | - // Activity |
|
42 | - $activity = $this->client->getReceiver(Client::ACTIVITY); |
|
43 | - $activity->setRepo('GitHubAPI'); |
|
44 | - $activity->setOwner('FlexyProject'); |
|
45 | - |
|
46 | - // Events |
|
47 | - $this->events = $activity->getReceiver(Activity::EVENTS); |
|
48 | - |
|
49 | - // Feeds |
|
50 | - $this->feeds = $activity->getReceiver(Activity::FEEDS); |
|
51 | - |
|
52 | - // Notifications |
|
53 | - $this->notifications = $activity->getReceiver(Activity::NOTIFICATIONS); |
|
54 | - |
|
55 | - // Starring |
|
56 | - $this->starring = $activity->getReceiver(Activity::STARRING); |
|
57 | - |
|
58 | - // Watching |
|
59 | - $this->watching = $activity->getReceiver(Activity::WATCHING); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Test instance of Events's class |
|
64 | - */ |
|
65 | - public function testEvents() |
|
66 | - { |
|
67 | - $this->assertInstanceOf(Activity\Events::class, $this->events); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Test instance of Feeds's class |
|
72 | - */ |
|
73 | - public function testFeeds() |
|
74 | - { |
|
75 | - $this->assertInstanceOf(Activity\Feeds::class, $this->feeds); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Test instance of Notifications's class |
|
80 | - */ |
|
81 | - public function testNotifications() |
|
82 | - { |
|
83 | - $this->assertInstanceOf(Activity\Notifications::class, $this->notifications); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Test instance of Starring's class |
|
88 | - */ |
|
89 | - public function testStarring() |
|
90 | - { |
|
91 | - $this->assertInstanceOf(Activity\Starring::class, $this->starring); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Test instance of Watching's class |
|
96 | - */ |
|
97 | - public function testWatching() |
|
98 | - { |
|
99 | - $this->assertInstanceOf(Activity\Watching::class, $this->watching); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Test listing public events |
|
104 | - */ |
|
105 | - public function testListPublicEvents() |
|
106 | - { |
|
107 | - $events = $this->events->listPublicEvents(); |
|
108 | - if (!empty($events)) { |
|
109 | - $event = array_pop($events); |
|
110 | - |
|
111 | - $this->assertArrayHasKey('id', $event); |
|
112 | - $this->assertArrayHasKey('type', $event); |
|
113 | - $this->assertArrayHasKey('actor', $event); |
|
114 | - $this->assertArrayHasKey('repo', $event); |
|
115 | - $this->assertArrayHasKey('payload', $event); |
|
116 | - $this->assertArrayHasKey('public', $event); |
|
117 | - $this->assertArrayHasKey('created_at', $event); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Test listing repository events |
|
123 | - */ |
|
124 | - public function testListRepositoryEvents() |
|
125 | - { |
|
126 | - $events = $this->events->listRepositoryEvents(); |
|
127 | - if (!empty($events)) { |
|
128 | - $event = array_pop($events); |
|
129 | - |
|
130 | - $this->assertArrayHasKey('id', $event); |
|
131 | - $this->assertArrayHasKey('type', $event); |
|
132 | - $this->assertArrayHasKey('actor', $event); |
|
133 | - $this->assertArrayHasKey('repo', $event); |
|
134 | - $this->assertArrayHasKey('payload', $event); |
|
135 | - $this->assertArrayHasKey('public', $event); |
|
136 | - $this->assertArrayHasKey('created_at', $event); |
|
137 | - $this->assertArrayHasKey('org', $event); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Test listing issues events |
|
143 | - */ |
|
144 | - public function testListIssueEvents() |
|
145 | - { |
|
146 | - $events = $this->events->listIssueEvents(); |
|
147 | - if (!empty($events)) { |
|
148 | - $event = array_pop($events); |
|
149 | - |
|
150 | - $this->assertArrayHasKey('id', $event); |
|
151 | - $this->assertArrayHasKey('url', $event); |
|
152 | - $this->assertArrayHasKey('actor', $event); |
|
153 | - $this->assertArrayHasKey('event', $event); |
|
154 | - $this->assertArrayHasKey('issue', $event); |
|
155 | - $this->assertArrayHasKey('created_at', $event); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Test listing public network events |
|
161 | - */ |
|
162 | - public function testListPublicNetworkEvents() |
|
163 | - { |
|
164 | - $events = $this->events->listPublicNetworkEvents(); |
|
165 | - if (!empty($events)) { |
|
166 | - $event = array_pop($events); |
|
167 | - |
|
168 | - $this->assertArrayHasKey('id', $event); |
|
169 | - $this->assertArrayHasKey('type', $event); |
|
170 | - $this->assertArrayHasKey('actor', $event); |
|
171 | - $this->assertArrayHasKey('repo', $event); |
|
172 | - $this->assertArrayHasKey('payload', $event); |
|
173 | - $this->assertArrayHasKey('public', $event); |
|
174 | - $this->assertArrayHasKey('created_at', $event); |
|
175 | - $this->assertArrayHasKey('org', $event); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Test listing public organization events |
|
181 | - */ |
|
182 | - public function testListPublicOrganizationEvents() |
|
183 | - { |
|
184 | - $events = $this->events->listPublicOrganizationEvents($GLOBALS['ORGANIZATION']); |
|
185 | - if (!empty($events)) { |
|
186 | - $event = array_pop($events); |
|
187 | - |
|
188 | - $this->assertArrayHasKey('id', $event); |
|
189 | - $this->assertArrayHasKey('type', $event); |
|
190 | - $this->assertArrayHasKey('actor', $event); |
|
191 | - $this->assertArrayHasKey('repo', $event); |
|
192 | - $this->assertArrayHasKey('payload', $event); |
|
193 | - $this->assertArrayHasKey('public', $event); |
|
194 | - $this->assertArrayHasKey('created_at', $event); |
|
195 | - $this->assertArrayHasKey('org', $event); |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Test listing user receive events |
|
201 | - */ |
|
202 | - public function testListUserReceiveEvents() |
|
203 | - { |
|
204 | - $events = $this->events->listUserReceiveEvents($GLOBALS['USERNAME']); |
|
205 | - if (!empty($events)) { |
|
206 | - $event = array_pop($events); |
|
207 | - |
|
208 | - $this->assertArrayHasKey('id', $event); |
|
209 | - $this->assertArrayHasKey('type', $event); |
|
210 | - $this->assertArrayHasKey('actor', $event); |
|
211 | - $this->assertArrayHasKey('repo', $event); |
|
212 | - $this->assertArrayHasKey('payload', $event); |
|
213 | - $this->assertArrayHasKey('public', $event); |
|
214 | - $this->assertArrayHasKey('created_at', $event); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Test listing public user receive events |
|
220 | - */ |
|
221 | - public function testListPublicUserReceiveEvents() |
|
222 | - { |
|
223 | - $events = $this->events->listPublicUserReceiveEvents($GLOBALS['USERNAME']); |
|
224 | - if (!empty($events)) { |
|
225 | - $event = array_pop($events); |
|
226 | - |
|
227 | - $this->assertArrayHasKey('id', $event); |
|
228 | - $this->assertArrayHasKey('type', $event); |
|
229 | - $this->assertArrayHasKey('actor', $event); |
|
230 | - $this->assertArrayHasKey('repo', $event); |
|
231 | - $this->assertArrayHasKey('payload', $event); |
|
232 | - $this->assertArrayHasKey('public', $event); |
|
233 | - $this->assertArrayHasKey('created_at', $event); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Test listing user preformed events |
|
239 | - */ |
|
240 | - public function testListUserPerformedEvents() |
|
241 | - { |
|
242 | - $events = $this->events->listUserPerformedEvents($GLOBALS['USERNAME']); |
|
243 | - if (!empty($events)) { |
|
244 | - $event = array_pop($events); |
|
245 | - |
|
246 | - $this->assertArrayHasKey('id', $event); |
|
247 | - $this->assertArrayHasKey('type', $event); |
|
248 | - $this->assertArrayHasKey('actor', $event); |
|
249 | - $this->assertArrayHasKey('repo', $event); |
|
250 | - $this->assertArrayHasKey('payload', $event); |
|
251 | - $this->assertArrayHasKey('public', $event); |
|
252 | - $this->assertArrayHasKey('created_at', $event); |
|
253 | - $this->assertArrayHasKey('org', $event); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Test listing public user performed events |
|
259 | - */ |
|
260 | - public function testListPublicUserPerformedEvents() |
|
261 | - { |
|
262 | - $events = $this->events->listPublicUserPerformedEvents($GLOBALS['USERNAME']); |
|
263 | - if (!empty($events)) { |
|
264 | - $event = array_pop($events); |
|
265 | - |
|
266 | - $this->assertArrayHasKey('id', $event); |
|
267 | - $this->assertArrayHasKey('type', $event); |
|
268 | - $this->assertArrayHasKey('actor', $event); |
|
269 | - $this->assertArrayHasKey('repo', $event); |
|
270 | - $this->assertArrayHasKey('payload', $event); |
|
271 | - $this->assertArrayHasKey('public', $event); |
|
272 | - $this->assertArrayHasKey('created_at', $event); |
|
273 | - $this->assertArrayHasKey('org', $event); |
|
274 | - } |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Test listing organization events |
|
279 | - */ |
|
280 | - public function testListOrganizationEvents() |
|
281 | - { |
|
282 | - $events = $this->events->listOrganizationEvents($GLOBALS['USERNAME'], $GLOBALS['ORGANIZATION']); |
|
283 | - if (!empty($events)) { |
|
284 | - $event = array_pop($events); |
|
285 | - |
|
286 | - $this->assertArrayHasKey('id', $event); |
|
287 | - $this->assertArrayHasKey('type', $event); |
|
288 | - $this->assertArrayHasKey('actor', $event); |
|
289 | - $this->assertArrayHasKey('repo', $event); |
|
290 | - $this->assertArrayHasKey('payload', $event); |
|
291 | - $this->assertArrayHasKey('public', $event); |
|
292 | - $this->assertArrayHasKey('created_at', $event); |
|
293 | - $this->assertArrayHasKey('org', $event); |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Test listing feeds |
|
299 | - */ |
|
300 | - public function testListFeeds() |
|
301 | - { |
|
302 | - $feeds = $this->feeds->listFeeds(); |
|
303 | - $this->assertArrayHasKey('timeline_url', $feeds); |
|
304 | - $this->assertArrayHasKey('user_url', $feeds); |
|
305 | - $this->assertArrayHasKey('current_user_public_url', $feeds); |
|
306 | - $this->assertArrayHasKey('current_user_url', $feeds); |
|
307 | - $this->assertArrayHasKey('current_user_actor_url', $feeds); |
|
308 | - $this->assertArrayHasKey('current_user_organization_url', $feeds); |
|
309 | - $this->assertArrayHasKey('current_user_organization_urls', $feeds); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Test listing notifications |
|
314 | - */ |
|
315 | - public function testListNotifications() |
|
316 | - { |
|
317 | - $notifications = $this->notifications->listNotifications(true, true, '2016-02-14'); |
|
318 | - if (!empty($notifications)) { |
|
319 | - $notification = array_pop($notifications); |
|
320 | - |
|
321 | - $this->assertArrayHasKey('id', $notification); |
|
322 | - $this->assertArrayHasKey('repository', $notification); |
|
323 | - $this->assertArrayHasKey('subject', $notification); |
|
324 | - $this->assertArrayHasKey('reason', $notification); |
|
325 | - $this->assertArrayHasKey('unread', $notification); |
|
326 | - $this->assertArrayHasKey('updated_at', $notification); |
|
327 | - $this->assertArrayHasKey('last_read_at', $notification); |
|
328 | - $this->assertArrayHasKey('url', $notification); |
|
329 | - } |
|
330 | - } |
|
15 | + /** @var Activity\Events */ |
|
16 | + protected $events; |
|
17 | + |
|
18 | + /** @var Activity\Feeds */ |
|
19 | + protected $feeds; |
|
20 | + |
|
21 | + /** @var Activity\Notifications */ |
|
22 | + protected $notifications; |
|
23 | + |
|
24 | + /** @var Activity\Starring */ |
|
25 | + protected $starring; |
|
26 | + |
|
27 | + /** @var Activity\Watching */ |
|
28 | + protected $watching; |
|
29 | + |
|
30 | + /** |
|
31 | + * ActivityTest constructor. |
|
32 | + * |
|
33 | + * @param null $name |
|
34 | + * @param array $data |
|
35 | + * @param string $dataName |
|
36 | + */ |
|
37 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
38 | + { |
|
39 | + parent::__construct($name, $data, $dataName); |
|
40 | + |
|
41 | + // Activity |
|
42 | + $activity = $this->client->getReceiver(Client::ACTIVITY); |
|
43 | + $activity->setRepo('GitHubAPI'); |
|
44 | + $activity->setOwner('FlexyProject'); |
|
45 | + |
|
46 | + // Events |
|
47 | + $this->events = $activity->getReceiver(Activity::EVENTS); |
|
48 | + |
|
49 | + // Feeds |
|
50 | + $this->feeds = $activity->getReceiver(Activity::FEEDS); |
|
51 | + |
|
52 | + // Notifications |
|
53 | + $this->notifications = $activity->getReceiver(Activity::NOTIFICATIONS); |
|
54 | + |
|
55 | + // Starring |
|
56 | + $this->starring = $activity->getReceiver(Activity::STARRING); |
|
57 | + |
|
58 | + // Watching |
|
59 | + $this->watching = $activity->getReceiver(Activity::WATCHING); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Test instance of Events's class |
|
64 | + */ |
|
65 | + public function testEvents() |
|
66 | + { |
|
67 | + $this->assertInstanceOf(Activity\Events::class, $this->events); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Test instance of Feeds's class |
|
72 | + */ |
|
73 | + public function testFeeds() |
|
74 | + { |
|
75 | + $this->assertInstanceOf(Activity\Feeds::class, $this->feeds); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Test instance of Notifications's class |
|
80 | + */ |
|
81 | + public function testNotifications() |
|
82 | + { |
|
83 | + $this->assertInstanceOf(Activity\Notifications::class, $this->notifications); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Test instance of Starring's class |
|
88 | + */ |
|
89 | + public function testStarring() |
|
90 | + { |
|
91 | + $this->assertInstanceOf(Activity\Starring::class, $this->starring); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Test instance of Watching's class |
|
96 | + */ |
|
97 | + public function testWatching() |
|
98 | + { |
|
99 | + $this->assertInstanceOf(Activity\Watching::class, $this->watching); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Test listing public events |
|
104 | + */ |
|
105 | + public function testListPublicEvents() |
|
106 | + { |
|
107 | + $events = $this->events->listPublicEvents(); |
|
108 | + if (!empty($events)) { |
|
109 | + $event = array_pop($events); |
|
110 | + |
|
111 | + $this->assertArrayHasKey('id', $event); |
|
112 | + $this->assertArrayHasKey('type', $event); |
|
113 | + $this->assertArrayHasKey('actor', $event); |
|
114 | + $this->assertArrayHasKey('repo', $event); |
|
115 | + $this->assertArrayHasKey('payload', $event); |
|
116 | + $this->assertArrayHasKey('public', $event); |
|
117 | + $this->assertArrayHasKey('created_at', $event); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Test listing repository events |
|
123 | + */ |
|
124 | + public function testListRepositoryEvents() |
|
125 | + { |
|
126 | + $events = $this->events->listRepositoryEvents(); |
|
127 | + if (!empty($events)) { |
|
128 | + $event = array_pop($events); |
|
129 | + |
|
130 | + $this->assertArrayHasKey('id', $event); |
|
131 | + $this->assertArrayHasKey('type', $event); |
|
132 | + $this->assertArrayHasKey('actor', $event); |
|
133 | + $this->assertArrayHasKey('repo', $event); |
|
134 | + $this->assertArrayHasKey('payload', $event); |
|
135 | + $this->assertArrayHasKey('public', $event); |
|
136 | + $this->assertArrayHasKey('created_at', $event); |
|
137 | + $this->assertArrayHasKey('org', $event); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Test listing issues events |
|
143 | + */ |
|
144 | + public function testListIssueEvents() |
|
145 | + { |
|
146 | + $events = $this->events->listIssueEvents(); |
|
147 | + if (!empty($events)) { |
|
148 | + $event = array_pop($events); |
|
149 | + |
|
150 | + $this->assertArrayHasKey('id', $event); |
|
151 | + $this->assertArrayHasKey('url', $event); |
|
152 | + $this->assertArrayHasKey('actor', $event); |
|
153 | + $this->assertArrayHasKey('event', $event); |
|
154 | + $this->assertArrayHasKey('issue', $event); |
|
155 | + $this->assertArrayHasKey('created_at', $event); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Test listing public network events |
|
161 | + */ |
|
162 | + public function testListPublicNetworkEvents() |
|
163 | + { |
|
164 | + $events = $this->events->listPublicNetworkEvents(); |
|
165 | + if (!empty($events)) { |
|
166 | + $event = array_pop($events); |
|
167 | + |
|
168 | + $this->assertArrayHasKey('id', $event); |
|
169 | + $this->assertArrayHasKey('type', $event); |
|
170 | + $this->assertArrayHasKey('actor', $event); |
|
171 | + $this->assertArrayHasKey('repo', $event); |
|
172 | + $this->assertArrayHasKey('payload', $event); |
|
173 | + $this->assertArrayHasKey('public', $event); |
|
174 | + $this->assertArrayHasKey('created_at', $event); |
|
175 | + $this->assertArrayHasKey('org', $event); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Test listing public organization events |
|
181 | + */ |
|
182 | + public function testListPublicOrganizationEvents() |
|
183 | + { |
|
184 | + $events = $this->events->listPublicOrganizationEvents($GLOBALS['ORGANIZATION']); |
|
185 | + if (!empty($events)) { |
|
186 | + $event = array_pop($events); |
|
187 | + |
|
188 | + $this->assertArrayHasKey('id', $event); |
|
189 | + $this->assertArrayHasKey('type', $event); |
|
190 | + $this->assertArrayHasKey('actor', $event); |
|
191 | + $this->assertArrayHasKey('repo', $event); |
|
192 | + $this->assertArrayHasKey('payload', $event); |
|
193 | + $this->assertArrayHasKey('public', $event); |
|
194 | + $this->assertArrayHasKey('created_at', $event); |
|
195 | + $this->assertArrayHasKey('org', $event); |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Test listing user receive events |
|
201 | + */ |
|
202 | + public function testListUserReceiveEvents() |
|
203 | + { |
|
204 | + $events = $this->events->listUserReceiveEvents($GLOBALS['USERNAME']); |
|
205 | + if (!empty($events)) { |
|
206 | + $event = array_pop($events); |
|
207 | + |
|
208 | + $this->assertArrayHasKey('id', $event); |
|
209 | + $this->assertArrayHasKey('type', $event); |
|
210 | + $this->assertArrayHasKey('actor', $event); |
|
211 | + $this->assertArrayHasKey('repo', $event); |
|
212 | + $this->assertArrayHasKey('payload', $event); |
|
213 | + $this->assertArrayHasKey('public', $event); |
|
214 | + $this->assertArrayHasKey('created_at', $event); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Test listing public user receive events |
|
220 | + */ |
|
221 | + public function testListPublicUserReceiveEvents() |
|
222 | + { |
|
223 | + $events = $this->events->listPublicUserReceiveEvents($GLOBALS['USERNAME']); |
|
224 | + if (!empty($events)) { |
|
225 | + $event = array_pop($events); |
|
226 | + |
|
227 | + $this->assertArrayHasKey('id', $event); |
|
228 | + $this->assertArrayHasKey('type', $event); |
|
229 | + $this->assertArrayHasKey('actor', $event); |
|
230 | + $this->assertArrayHasKey('repo', $event); |
|
231 | + $this->assertArrayHasKey('payload', $event); |
|
232 | + $this->assertArrayHasKey('public', $event); |
|
233 | + $this->assertArrayHasKey('created_at', $event); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Test listing user preformed events |
|
239 | + */ |
|
240 | + public function testListUserPerformedEvents() |
|
241 | + { |
|
242 | + $events = $this->events->listUserPerformedEvents($GLOBALS['USERNAME']); |
|
243 | + if (!empty($events)) { |
|
244 | + $event = array_pop($events); |
|
245 | + |
|
246 | + $this->assertArrayHasKey('id', $event); |
|
247 | + $this->assertArrayHasKey('type', $event); |
|
248 | + $this->assertArrayHasKey('actor', $event); |
|
249 | + $this->assertArrayHasKey('repo', $event); |
|
250 | + $this->assertArrayHasKey('payload', $event); |
|
251 | + $this->assertArrayHasKey('public', $event); |
|
252 | + $this->assertArrayHasKey('created_at', $event); |
|
253 | + $this->assertArrayHasKey('org', $event); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Test listing public user performed events |
|
259 | + */ |
|
260 | + public function testListPublicUserPerformedEvents() |
|
261 | + { |
|
262 | + $events = $this->events->listPublicUserPerformedEvents($GLOBALS['USERNAME']); |
|
263 | + if (!empty($events)) { |
|
264 | + $event = array_pop($events); |
|
265 | + |
|
266 | + $this->assertArrayHasKey('id', $event); |
|
267 | + $this->assertArrayHasKey('type', $event); |
|
268 | + $this->assertArrayHasKey('actor', $event); |
|
269 | + $this->assertArrayHasKey('repo', $event); |
|
270 | + $this->assertArrayHasKey('payload', $event); |
|
271 | + $this->assertArrayHasKey('public', $event); |
|
272 | + $this->assertArrayHasKey('created_at', $event); |
|
273 | + $this->assertArrayHasKey('org', $event); |
|
274 | + } |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Test listing organization events |
|
279 | + */ |
|
280 | + public function testListOrganizationEvents() |
|
281 | + { |
|
282 | + $events = $this->events->listOrganizationEvents($GLOBALS['USERNAME'], $GLOBALS['ORGANIZATION']); |
|
283 | + if (!empty($events)) { |
|
284 | + $event = array_pop($events); |
|
285 | + |
|
286 | + $this->assertArrayHasKey('id', $event); |
|
287 | + $this->assertArrayHasKey('type', $event); |
|
288 | + $this->assertArrayHasKey('actor', $event); |
|
289 | + $this->assertArrayHasKey('repo', $event); |
|
290 | + $this->assertArrayHasKey('payload', $event); |
|
291 | + $this->assertArrayHasKey('public', $event); |
|
292 | + $this->assertArrayHasKey('created_at', $event); |
|
293 | + $this->assertArrayHasKey('org', $event); |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Test listing feeds |
|
299 | + */ |
|
300 | + public function testListFeeds() |
|
301 | + { |
|
302 | + $feeds = $this->feeds->listFeeds(); |
|
303 | + $this->assertArrayHasKey('timeline_url', $feeds); |
|
304 | + $this->assertArrayHasKey('user_url', $feeds); |
|
305 | + $this->assertArrayHasKey('current_user_public_url', $feeds); |
|
306 | + $this->assertArrayHasKey('current_user_url', $feeds); |
|
307 | + $this->assertArrayHasKey('current_user_actor_url', $feeds); |
|
308 | + $this->assertArrayHasKey('current_user_organization_url', $feeds); |
|
309 | + $this->assertArrayHasKey('current_user_organization_urls', $feeds); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Test listing notifications |
|
314 | + */ |
|
315 | + public function testListNotifications() |
|
316 | + { |
|
317 | + $notifications = $this->notifications->listNotifications(true, true, '2016-02-14'); |
|
318 | + if (!empty($notifications)) { |
|
319 | + $notification = array_pop($notifications); |
|
320 | + |
|
321 | + $this->assertArrayHasKey('id', $notification); |
|
322 | + $this->assertArrayHasKey('repository', $notification); |
|
323 | + $this->assertArrayHasKey('subject', $notification); |
|
324 | + $this->assertArrayHasKey('reason', $notification); |
|
325 | + $this->assertArrayHasKey('unread', $notification); |
|
326 | + $this->assertArrayHasKey('updated_at', $notification); |
|
327 | + $this->assertArrayHasKey('last_read_at', $notification); |
|
328 | + $this->assertArrayHasKey('url', $notification); |
|
329 | + } |
|
330 | + } |
|
331 | 331 | } |
332 | 332 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace FlexyProject\GitHub\Tests\Receiver; |
3 | 3 | |
4 | 4 | use FlexyProject\GitHub\{ |
5 | - Client, Receiver\Gists, Tests\AbstractClientTest |
|
5 | + Client, Receiver\Gists, Tests\AbstractClientTest |
|
6 | 6 | }; |
7 | 7 | |
8 | 8 | /** |
@@ -12,343 +12,343 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GistsTest extends AbstractClientTest |
14 | 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 | - public function testListGists() |
|
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 | - public function testPublicListGists() |
|
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 | - public function testListUsersStarredGists() |
|
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 | - public function testListGistsCommit(string $gistId) |
|
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 | - } |
|
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 | + public function testListGists() |
|
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 | + public function testPublicListGists() |
|
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 | + public function testListUsersStarredGists() |
|
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 | + public function testListGistsCommit(string $gistId) |
|
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 | 353 | |
354 | 354 | } |
355 | 355 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace FlexyProject\GitHub\Tests\Receiver; |
3 | 3 | |
4 | 4 | use FlexyProject\GitHub\{ |
5 | - Client, Receiver\Miscellaneous, Tests\AbstractClientTest |
|
5 | + Client, Receiver\Miscellaneous, Tests\AbstractClientTest |
|
6 | 6 | }; |
7 | 7 | |
8 | 8 | /** |
@@ -13,209 +13,209 @@ discard block |
||
13 | 13 | class MiscellaneousTest extends AbstractClientTest |
14 | 14 | { |
15 | 15 | |
16 | - /** @var Miscellaneous */ |
|
17 | - protected $miscellaneous; |
|
18 | - |
|
19 | - /** @var Miscellaneous\Emojis */ |
|
20 | - protected $emojis; |
|
21 | - |
|
22 | - /** @var Miscellaneous\Gitignore */ |
|
23 | - protected $gitIgnore; |
|
24 | - |
|
25 | - /** @var Miscellaneous\Licenses */ |
|
26 | - protected $licenses; |
|
27 | - |
|
28 | - /** @var Miscellaneous\Markdown */ |
|
29 | - protected $markdown; |
|
30 | - |
|
31 | - /** @var Miscellaneous\Meta */ |
|
32 | - protected $meta; |
|
33 | - |
|
34 | - /** @var Miscellaneous\RateLimit */ |
|
35 | - protected $rateLimit; |
|
36 | - |
|
37 | - /** |
|
38 | - * MiscellaneousTest constructor. |
|
39 | - * |
|
40 | - * @param null $name |
|
41 | - * @param array $data |
|
42 | - * @param string $dataName |
|
43 | - */ |
|
44 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
45 | - { |
|
46 | - parent::__construct($name, $data, $dataName); |
|
47 | - |
|
48 | - // Miscellaneous |
|
49 | - $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); |
|
50 | - |
|
51 | - // Emojis |
|
52 | - $this->emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); |
|
53 | - |
|
54 | - // GitIgnore |
|
55 | - $this->gitIgnore = $this->miscellaneous->getReceiver(Miscellaneous::GITIGNORE); |
|
56 | - |
|
57 | - // Licenses |
|
58 | - $this->licenses = $this->miscellaneous->getReceiver(Miscellaneous::LICENSES); |
|
59 | - |
|
60 | - // Markdown |
|
61 | - $this->markdown = $this->miscellaneous->getReceiver(Miscellaneous::MARKDOWN); |
|
62 | - |
|
63 | - // Meta |
|
64 | - $this->meta = $this->miscellaneous->getReceiver(Miscellaneous::META); |
|
65 | - |
|
66 | - // RateLimit |
|
67 | - $this->rateLimit = $this->miscellaneous->getReceiver(Miscellaneous::RATE_LIMIT); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Test instance of Miscellaneous's class |
|
72 | - */ |
|
73 | - public function testMiscellaneous() |
|
74 | - { |
|
75 | - $this->assertInstanceOf(Miscellaneous::class, $this->miscellaneous); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Test instance of Emojis's class |
|
80 | - */ |
|
81 | - public function testEmojis() |
|
82 | - { |
|
83 | - $this->assertInstanceOf(Miscellaneous\Emojis::class, $this->emojis); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Test instance of Gitignore's class |
|
88 | - */ |
|
89 | - public function testGitIgnore() |
|
90 | - { |
|
91 | - $this->assertInstanceOf(Miscellaneous\Gitignore::class, $this->gitIgnore); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Test instance of Licenses's class |
|
96 | - */ |
|
97 | - public function testLicenses() |
|
98 | - { |
|
99 | - $this->assertInstanceOf(Miscellaneous\Licenses::class, $this->licenses); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Test instance of Markdown's class |
|
104 | - */ |
|
105 | - public function testMarkdown() |
|
106 | - { |
|
107 | - $this->assertInstanceOf(Miscellaneous\Markdown::class, $this->markdown); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Test instance of Meta's class |
|
112 | - */ |
|
113 | - public function testMeta() |
|
114 | - { |
|
115 | - $this->assertInstanceOf(Miscellaneous\Meta::class, $this->meta); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Test instance of 's class |
|
120 | - */ |
|
121 | - public function testRateLimit() |
|
122 | - { |
|
123 | - $this->assertInstanceOf(Miscellaneous\RateLimit::class, $this->rateLimit); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Test list available Emojis |
|
128 | - */ |
|
129 | - public function testGetListEmojis() |
|
130 | - { |
|
131 | - $this->assertCount(1508, $this->emojis->get()); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Test listing available templates |
|
136 | - */ |
|
137 | - public function testListingAvailableTemplates() |
|
138 | - { |
|
139 | - $templates = $this->gitIgnore->listingAvailableTemplates(); |
|
140 | - |
|
141 | - $this->assertContains('Android', $templates); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Test getting a single template |
|
146 | - */ |
|
147 | - public function testGetSingleTemplate() |
|
148 | - { |
|
149 | - $template = $this->gitIgnore->getSingleTemplate('Android'); |
|
150 | - |
|
151 | - $this->assertArrayHasKey('name', $template); |
|
152 | - $this->assertArrayHasKey('source', $template); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Test listing all licenses |
|
157 | - */ |
|
158 | - public function testListAllLicenses() |
|
159 | - { |
|
160 | - $licenses = $this->licenses->listAllLicenses(); |
|
161 | - $license = array_pop($licenses); |
|
162 | - |
|
163 | - $this->assertArrayHasKey('key', $license); |
|
164 | - $this->assertArrayHasKey('name', $license); |
|
165 | - $this->assertArrayHasKey('spdx_id', $license); |
|
166 | - $this->assertArrayHasKey('url', $license); |
|
167 | - $this->assertArrayHasKey('featured', $license); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Test getting individual license |
|
172 | - */ |
|
173 | - public function testGettingIndividualLicense() |
|
174 | - { |
|
175 | - $license = $this->licenses->getIndividualLicense('mit'); |
|
176 | - |
|
177 | - $this->assertArrayHasKey('body', $license); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Test render markdown text |
|
182 | - */ |
|
183 | - public function testRender() |
|
184 | - { |
|
185 | - $output = $this->markdown->render('Hello world FlexyProject/GitHubAPI#43 **cool**, and #43!'); |
|
186 | - |
|
187 | - $this->assertEquals('<p>Hello world FlexyProject/GitHubAPI#43 <strong>cool</strong>, and #43!</p>', |
|
188 | - str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Test render markdown raw text |
|
193 | - */ |
|
194 | - public function testRenderRaw() |
|
195 | - { |
|
196 | - $output = $this->markdown->renderRaw('**cool**'); |
|
197 | - |
|
198 | - $this->assertEquals('<p>{"file":"<strong>cool</strong>"}</p>', |
|
199 | - str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Test getting meta about GitHub.com |
|
204 | - */ |
|
205 | - public function testGetMeta() |
|
206 | - { |
|
207 | - $meta = $this->meta->get(); |
|
208 | - |
|
209 | - $this->assertTrue($meta['verifiable_password_authentication']); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Test rate limit |
|
214 | - */ |
|
215 | - public function testRate() |
|
216 | - { |
|
217 | - $rateLimit = $this->rateLimit->get(); |
|
218 | - |
|
219 | - $this->assertArrayHasKey('rate', $rateLimit); |
|
220 | - } |
|
16 | + /** @var Miscellaneous */ |
|
17 | + protected $miscellaneous; |
|
18 | + |
|
19 | + /** @var Miscellaneous\Emojis */ |
|
20 | + protected $emojis; |
|
21 | + |
|
22 | + /** @var Miscellaneous\Gitignore */ |
|
23 | + protected $gitIgnore; |
|
24 | + |
|
25 | + /** @var Miscellaneous\Licenses */ |
|
26 | + protected $licenses; |
|
27 | + |
|
28 | + /** @var Miscellaneous\Markdown */ |
|
29 | + protected $markdown; |
|
30 | + |
|
31 | + /** @var Miscellaneous\Meta */ |
|
32 | + protected $meta; |
|
33 | + |
|
34 | + /** @var Miscellaneous\RateLimit */ |
|
35 | + protected $rateLimit; |
|
36 | + |
|
37 | + /** |
|
38 | + * MiscellaneousTest constructor. |
|
39 | + * |
|
40 | + * @param null $name |
|
41 | + * @param array $data |
|
42 | + * @param string $dataName |
|
43 | + */ |
|
44 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
45 | + { |
|
46 | + parent::__construct($name, $data, $dataName); |
|
47 | + |
|
48 | + // Miscellaneous |
|
49 | + $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); |
|
50 | + |
|
51 | + // Emojis |
|
52 | + $this->emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); |
|
53 | + |
|
54 | + // GitIgnore |
|
55 | + $this->gitIgnore = $this->miscellaneous->getReceiver(Miscellaneous::GITIGNORE); |
|
56 | + |
|
57 | + // Licenses |
|
58 | + $this->licenses = $this->miscellaneous->getReceiver(Miscellaneous::LICENSES); |
|
59 | + |
|
60 | + // Markdown |
|
61 | + $this->markdown = $this->miscellaneous->getReceiver(Miscellaneous::MARKDOWN); |
|
62 | + |
|
63 | + // Meta |
|
64 | + $this->meta = $this->miscellaneous->getReceiver(Miscellaneous::META); |
|
65 | + |
|
66 | + // RateLimit |
|
67 | + $this->rateLimit = $this->miscellaneous->getReceiver(Miscellaneous::RATE_LIMIT); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Test instance of Miscellaneous's class |
|
72 | + */ |
|
73 | + public function testMiscellaneous() |
|
74 | + { |
|
75 | + $this->assertInstanceOf(Miscellaneous::class, $this->miscellaneous); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Test instance of Emojis's class |
|
80 | + */ |
|
81 | + public function testEmojis() |
|
82 | + { |
|
83 | + $this->assertInstanceOf(Miscellaneous\Emojis::class, $this->emojis); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Test instance of Gitignore's class |
|
88 | + */ |
|
89 | + public function testGitIgnore() |
|
90 | + { |
|
91 | + $this->assertInstanceOf(Miscellaneous\Gitignore::class, $this->gitIgnore); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Test instance of Licenses's class |
|
96 | + */ |
|
97 | + public function testLicenses() |
|
98 | + { |
|
99 | + $this->assertInstanceOf(Miscellaneous\Licenses::class, $this->licenses); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Test instance of Markdown's class |
|
104 | + */ |
|
105 | + public function testMarkdown() |
|
106 | + { |
|
107 | + $this->assertInstanceOf(Miscellaneous\Markdown::class, $this->markdown); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Test instance of Meta's class |
|
112 | + */ |
|
113 | + public function testMeta() |
|
114 | + { |
|
115 | + $this->assertInstanceOf(Miscellaneous\Meta::class, $this->meta); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Test instance of 's class |
|
120 | + */ |
|
121 | + public function testRateLimit() |
|
122 | + { |
|
123 | + $this->assertInstanceOf(Miscellaneous\RateLimit::class, $this->rateLimit); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Test list available Emojis |
|
128 | + */ |
|
129 | + public function testGetListEmojis() |
|
130 | + { |
|
131 | + $this->assertCount(1508, $this->emojis->get()); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Test listing available templates |
|
136 | + */ |
|
137 | + public function testListingAvailableTemplates() |
|
138 | + { |
|
139 | + $templates = $this->gitIgnore->listingAvailableTemplates(); |
|
140 | + |
|
141 | + $this->assertContains('Android', $templates); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Test getting a single template |
|
146 | + */ |
|
147 | + public function testGetSingleTemplate() |
|
148 | + { |
|
149 | + $template = $this->gitIgnore->getSingleTemplate('Android'); |
|
150 | + |
|
151 | + $this->assertArrayHasKey('name', $template); |
|
152 | + $this->assertArrayHasKey('source', $template); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Test listing all licenses |
|
157 | + */ |
|
158 | + public function testListAllLicenses() |
|
159 | + { |
|
160 | + $licenses = $this->licenses->listAllLicenses(); |
|
161 | + $license = array_pop($licenses); |
|
162 | + |
|
163 | + $this->assertArrayHasKey('key', $license); |
|
164 | + $this->assertArrayHasKey('name', $license); |
|
165 | + $this->assertArrayHasKey('spdx_id', $license); |
|
166 | + $this->assertArrayHasKey('url', $license); |
|
167 | + $this->assertArrayHasKey('featured', $license); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Test getting individual license |
|
172 | + */ |
|
173 | + public function testGettingIndividualLicense() |
|
174 | + { |
|
175 | + $license = $this->licenses->getIndividualLicense('mit'); |
|
176 | + |
|
177 | + $this->assertArrayHasKey('body', $license); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Test render markdown text |
|
182 | + */ |
|
183 | + public function testRender() |
|
184 | + { |
|
185 | + $output = $this->markdown->render('Hello world FlexyProject/GitHubAPI#43 **cool**, and #43!'); |
|
186 | + |
|
187 | + $this->assertEquals('<p>Hello world FlexyProject/GitHubAPI#43 <strong>cool</strong>, and #43!</p>', |
|
188 | + str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Test render markdown raw text |
|
193 | + */ |
|
194 | + public function testRenderRaw() |
|
195 | + { |
|
196 | + $output = $this->markdown->renderRaw('**cool**'); |
|
197 | + |
|
198 | + $this->assertEquals('<p>{"file":"<strong>cool</strong>"}</p>', |
|
199 | + str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Test getting meta about GitHub.com |
|
204 | + */ |
|
205 | + public function testGetMeta() |
|
206 | + { |
|
207 | + $meta = $this->meta->get(); |
|
208 | + |
|
209 | + $this->assertTrue($meta['verifiable_password_authentication']); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Test rate limit |
|
214 | + */ |
|
215 | + public function testRate() |
|
216 | + { |
|
217 | + $rateLimit = $this->rateLimit->get(); |
|
218 | + |
|
219 | + $this->assertArrayHasKey('rate', $rateLimit); |
|
220 | + } |
|
221 | 221 | } |
222 | 222 | \ No newline at end of file |
@@ -11,24 +11,24 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class AbstractClientTest extends TestCase |
13 | 13 | { |
14 | - /** @var Client */ |
|
15 | - protected $client; |
|
14 | + /** @var Client */ |
|
15 | + protected $client; |
|
16 | 16 | |
17 | - /** |
|
18 | - * AbstractTest constructor. |
|
19 | - * |
|
20 | - * @param null $name |
|
21 | - * @param array $data |
|
22 | - * @param string $dataName |
|
23 | - */ |
|
24 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
25 | - { |
|
26 | - // Create a client object |
|
27 | - $this->client = new Client(); |
|
17 | + /** |
|
18 | + * AbstractTest constructor. |
|
19 | + * |
|
20 | + * @param null $name |
|
21 | + * @param array $data |
|
22 | + * @param string $dataName |
|
23 | + */ |
|
24 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
25 | + { |
|
26 | + // Create a client object |
|
27 | + $this->client = new Client(); |
|
28 | 28 | |
29 | - // Set auth credentials |
|
30 | - $this->client->setHttpAuth($GLOBALS['USERNAME'], $GLOBALS['PASSWORD']); |
|
29 | + // Set auth credentials |
|
30 | + $this->client->setHttpAuth($GLOBALS['USERNAME'], $GLOBALS['PASSWORD']); |
|
31 | 31 | |
32 | - parent::__construct($name, $data, $dataName); |
|
33 | - } |
|
32 | + parent::__construct($name, $data, $dataName); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | use FlexyProject\GitHub\Client; |
5 | 5 | use FlexyProject\GitHub\Receiver\{ |
6 | - Activity, Enterprise, Gists, GitData, Issues, Miscellaneous, Organizations, PullRequests, Repositories, Search, Users |
|
6 | + Activity, Enterprise, Gists, GitData, Issues, Miscellaneous, Organizations, PullRequests, Repositories, Search, Users |
|
7 | 7 | }; |
8 | 8 | |
9 | 9 | /** |
@@ -14,99 +14,99 @@ discard block |
||
14 | 14 | class ClientTest extends AbstractClientTest |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Test instance of Client's class |
|
19 | - */ |
|
20 | - public function testClient() |
|
21 | - { |
|
22 | - $this->assertInstanceOf(Client::class, $this->client); |
|
23 | - } |
|
17 | + /** |
|
18 | + * Test instance of Client's class |
|
19 | + */ |
|
20 | + public function testClient() |
|
21 | + { |
|
22 | + $this->assertInstanceOf(Client::class, $this->client); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Test instance of Activity's class |
|
27 | - */ |
|
28 | - public function testActivityReceiver() |
|
29 | - { |
|
30 | - $this->assertInstanceOf(Activity::class, $this->client->getReceiver(Client::ACTIVITY)); |
|
31 | - } |
|
25 | + /** |
|
26 | + * Test instance of Activity's class |
|
27 | + */ |
|
28 | + public function testActivityReceiver() |
|
29 | + { |
|
30 | + $this->assertInstanceOf(Activity::class, $this->client->getReceiver(Client::ACTIVITY)); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Test instance of Enterprise's class |
|
35 | - */ |
|
36 | - public function testEnterpriseReceiver() |
|
37 | - { |
|
38 | - $this->assertInstanceOf(Enterprise::class, $this->client->getReceiver(Client::ENTERPRISE)); |
|
39 | - } |
|
33 | + /** |
|
34 | + * Test instance of Enterprise's class |
|
35 | + */ |
|
36 | + public function testEnterpriseReceiver() |
|
37 | + { |
|
38 | + $this->assertInstanceOf(Enterprise::class, $this->client->getReceiver(Client::ENTERPRISE)); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Test instance of Gists's class |
|
43 | - */ |
|
44 | - public function testGistsReceiver() |
|
45 | - { |
|
46 | - $this->assertInstanceOf(Gists::class, $this->client->getReceiver(Client::GISTS)); |
|
47 | - } |
|
41 | + /** |
|
42 | + * Test instance of Gists's class |
|
43 | + */ |
|
44 | + public function testGistsReceiver() |
|
45 | + { |
|
46 | + $this->assertInstanceOf(Gists::class, $this->client->getReceiver(Client::GISTS)); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Test instance of GitData's class |
|
51 | - */ |
|
52 | - public function testGitDataReceiver() |
|
53 | - { |
|
54 | - $this->assertInstanceOf(GitData::class, $this->client->getReceiver(Client::GIT_DATA)); |
|
55 | - } |
|
49 | + /** |
|
50 | + * Test instance of GitData's class |
|
51 | + */ |
|
52 | + public function testGitDataReceiver() |
|
53 | + { |
|
54 | + $this->assertInstanceOf(GitData::class, $this->client->getReceiver(Client::GIT_DATA)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Test instance of Issues's class |
|
59 | - */ |
|
60 | - public function testIssuesReceiver() |
|
61 | - { |
|
62 | - $this->assertInstanceOf(Issues::class, $this->client->getReceiver(Client::ISSUES)); |
|
63 | - } |
|
57 | + /** |
|
58 | + * Test instance of Issues's class |
|
59 | + */ |
|
60 | + public function testIssuesReceiver() |
|
61 | + { |
|
62 | + $this->assertInstanceOf(Issues::class, $this->client->getReceiver(Client::ISSUES)); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Test instance of Miscellaneous's class |
|
67 | - */ |
|
68 | - public function testMiscellaneousReceiver() |
|
69 | - { |
|
70 | - $this->assertInstanceOf(Miscellaneous::class, $this->client->getReceiver(Client::MISCELLANEOUS)); |
|
71 | - } |
|
65 | + /** |
|
66 | + * Test instance of Miscellaneous's class |
|
67 | + */ |
|
68 | + public function testMiscellaneousReceiver() |
|
69 | + { |
|
70 | + $this->assertInstanceOf(Miscellaneous::class, $this->client->getReceiver(Client::MISCELLANEOUS)); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Test instance of Organizations's class |
|
75 | - */ |
|
76 | - public function testOrganizationsReceiver() |
|
77 | - { |
|
78 | - $this->assertInstanceOf(Organizations::class, $this->client->getReceiver(Client::ORGANIZATIONS)); |
|
79 | - } |
|
73 | + /** |
|
74 | + * Test instance of Organizations's class |
|
75 | + */ |
|
76 | + public function testOrganizationsReceiver() |
|
77 | + { |
|
78 | + $this->assertInstanceOf(Organizations::class, $this->client->getReceiver(Client::ORGANIZATIONS)); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Test instance of PullRequests's class |
|
83 | - */ |
|
84 | - public function testPullRequestsReceiver() |
|
85 | - { |
|
86 | - $this->assertInstanceOf(PullRequests::class, $this->client->getReceiver(Client::PULL_REQUESTS)); |
|
87 | - } |
|
81 | + /** |
|
82 | + * Test instance of PullRequests's class |
|
83 | + */ |
|
84 | + public function testPullRequestsReceiver() |
|
85 | + { |
|
86 | + $this->assertInstanceOf(PullRequests::class, $this->client->getReceiver(Client::PULL_REQUESTS)); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Test instance of Repositories's class |
|
91 | - */ |
|
92 | - public function testRepositoriesReceiver() |
|
93 | - { |
|
94 | - $this->assertInstanceOf(Repositories::class, $this->client->getReceiver(Client::REPOSITORIES)); |
|
95 | - } |
|
89 | + /** |
|
90 | + * Test instance of Repositories's class |
|
91 | + */ |
|
92 | + public function testRepositoriesReceiver() |
|
93 | + { |
|
94 | + $this->assertInstanceOf(Repositories::class, $this->client->getReceiver(Client::REPOSITORIES)); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Test instance of Search's class |
|
99 | - */ |
|
100 | - public function testSearchReceiver() |
|
101 | - { |
|
102 | - $this->assertInstanceOf(Search::class, $this->client->getReceiver(Client::SEARCH)); |
|
103 | - } |
|
97 | + /** |
|
98 | + * Test instance of Search's class |
|
99 | + */ |
|
100 | + public function testSearchReceiver() |
|
101 | + { |
|
102 | + $this->assertInstanceOf(Search::class, $this->client->getReceiver(Client::SEARCH)); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Test instance of Users's class |
|
107 | - */ |
|
108 | - public function testUsersReceiver() |
|
109 | - { |
|
110 | - $this->assertInstanceOf(Users::class, $this->client->getReceiver(Client::USERS)); |
|
111 | - } |
|
105 | + /** |
|
106 | + * Test instance of Users's class |
|
107 | + */ |
|
108 | + public function testUsersReceiver() |
|
109 | + { |
|
110 | + $this->assertInstanceOf(Users::class, $this->client->getReceiver(Client::USERS)); |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -12,27 +12,27 @@ |
||
12 | 12 | */ |
13 | 13 | class AbstractWebHookTest extends TestCase |
14 | 14 | { |
15 | - /** @var WebHook */ |
|
16 | - protected $webHook; |
|
15 | + /** @var WebHook */ |
|
16 | + protected $webHook; |
|
17 | 17 | |
18 | - /** @var Payload */ |
|
19 | - protected $payload; |
|
18 | + /** @var Payload */ |
|
19 | + protected $payload; |
|
20 | 20 | |
21 | - /** |
|
22 | - * WebHookTest constructor. |
|
23 | - * |
|
24 | - * @param null $name |
|
25 | - * @param array $data |
|
26 | - * @param string $dataName |
|
27 | - */ |
|
28 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
29 | - { |
|
30 | - // Create a WebHook object |
|
31 | - $this->webHook = new WebHook(); |
|
21 | + /** |
|
22 | + * WebHookTest constructor. |
|
23 | + * |
|
24 | + * @param null $name |
|
25 | + * @param array $data |
|
26 | + * @param string $dataName |
|
27 | + */ |
|
28 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
29 | + { |
|
30 | + // Create a WebHook object |
|
31 | + $this->webHook = new WebHook(); |
|
32 | 32 | |
33 | - // Create a Payload object |
|
34 | - $this->payload = $this->webHook->getEvent(WebHook::PAYLOAD); |
|
33 | + // Create a Payload object |
|
34 | + $this->payload = $this->webHook->getEvent(WebHook::PAYLOAD); |
|
35 | 35 | |
36 | - parent::__construct($name, $data, $dataName); |
|
37 | - } |
|
36 | + parent::__construct($name, $data, $dataName); |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |