@@ -12,24 +12,24 @@ |
||
12 | 12 | class WebHook extends AbstractApi |
13 | 13 | { |
14 | 14 | |
15 | - /** Constants */ |
|
16 | - const PAYLOAD = 'Payload'; |
|
15 | + /** Constants */ |
|
16 | + const PAYLOAD = 'Payload'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Returns Event object |
|
20 | - * |
|
21 | - * @param string $event |
|
22 | - * |
|
23 | - * @return null|EventInterface |
|
24 | - */ |
|
25 | - public function getEvent(string $event) |
|
26 | - { |
|
27 | - $class = (string)$this->sprintf(':namespace\Event\:event', __NAMESPACE__, $event); |
|
18 | + /** |
|
19 | + * Returns Event object |
|
20 | + * |
|
21 | + * @param string $event |
|
22 | + * |
|
23 | + * @return null|EventInterface |
|
24 | + */ |
|
25 | + public function getEvent(string $event) |
|
26 | + { |
|
27 | + $class = (string)$this->sprintf(':namespace\Event\:event', __NAMESPACE__, $event); |
|
28 | 28 | |
29 | - if (class_exists($class)) { |
|
30 | - return new $class($this); |
|
31 | - } |
|
29 | + if (class_exists($class)) { |
|
30 | + return new $class($this); |
|
31 | + } |
|
32 | 32 | |
33 | - return null; |
|
34 | - } |
|
33 | + return null; |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -11,17 +11,17 @@ |
||
11 | 11 | interface EventInterface |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Constructor, pass a WebHook object |
|
16 | - * |
|
17 | - * @param WebHook $webHook |
|
18 | - */ |
|
19 | - public function __construct(WebHook $webHook); |
|
14 | + /** |
|
15 | + * Constructor, pass a WebHook object |
|
16 | + * |
|
17 | + * @param WebHook $webHook |
|
18 | + */ |
|
19 | + public function __construct(WebHook $webHook); |
|
20 | 20 | |
21 | - /** |
|
22 | - * Parse raw data |
|
23 | - * |
|
24 | - * @return Payload |
|
25 | - */ |
|
26 | - public function parse(): Payload; |
|
21 | + /** |
|
22 | + * Parse raw data |
|
23 | + * |
|
24 | + * @return Payload |
|
25 | + */ |
|
26 | + public function parse(): Payload; |
|
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -13,190 +13,190 @@ |
||
13 | 13 | class Payload implements EventInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** Protected properties */ |
|
17 | - protected $webHook; |
|
18 | - protected $secret = null; |
|
19 | - protected $rawData; |
|
20 | - protected $parsedData; |
|
21 | - |
|
22 | - /** |
|
23 | - * Constructor, pass a WebHook object |
|
24 | - * |
|
25 | - * @param WebHook $webHook |
|
26 | - */ |
|
27 | - public function __construct(WebHook $webHook) |
|
28 | - { |
|
29 | - $this->setWebHook($webHook); |
|
30 | - $this->setRawData($webHook->getRequest()->getContent()); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Get webHook |
|
35 | - * |
|
36 | - * @return null|WebHook |
|
37 | - */ |
|
38 | - public function getWebHook() |
|
39 | - { |
|
40 | - return $this->webHook; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Set webHook |
|
45 | - * |
|
46 | - * @param mixed $webHook |
|
47 | - * |
|
48 | - * @return Payload |
|
49 | - */ |
|
50 | - public function setWebHook($webHook): Payload |
|
51 | - { |
|
52 | - $this->webHook = $webHook; |
|
53 | - |
|
54 | - return $this; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Set secret, encode this secret with Hmac, SHA1 method |
|
59 | - * |
|
60 | - * @param string $secret |
|
61 | - * |
|
62 | - * @return Payload |
|
63 | - */ |
|
64 | - public function setSecret(string $secret): Payload |
|
65 | - { |
|
66 | - $this->secret = hash_hmac('sha1', $this->rawData, $secret); |
|
67 | - |
|
68 | - return $this; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Get secret |
|
73 | - * |
|
74 | - * @return null|string |
|
75 | - */ |
|
76 | - public function getSecret() |
|
77 | - { |
|
78 | - return $this->secret; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Get rawData |
|
83 | - * |
|
84 | - * @return resource|string |
|
85 | - */ |
|
86 | - public function getRawData() |
|
87 | - { |
|
88 | - return $this->rawData; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Set rawData |
|
93 | - * |
|
94 | - * @param resource|string $rawData |
|
95 | - * |
|
96 | - * @return Payload |
|
97 | - */ |
|
98 | - public function setRawData($rawData): Payload |
|
99 | - { |
|
100 | - $this->rawData = $rawData; |
|
101 | - |
|
102 | - return $this; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Get parsedData |
|
107 | - * |
|
108 | - * @return mixed |
|
109 | - */ |
|
110 | - public function getData() |
|
111 | - { |
|
112 | - return $this->parsedData; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Set parsedData |
|
117 | - * |
|
118 | - * @param mixed $parsedData |
|
119 | - * |
|
120 | - * @return Payload |
|
121 | - */ |
|
122 | - protected function setParsedData($parsedData): Payload |
|
123 | - { |
|
124 | - $data = json_decode($parsedData); |
|
125 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
126 | - $this->parsedData = $data; |
|
127 | - } |
|
128 | - |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Debugger |
|
134 | - * |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function __debugInfo(): array |
|
138 | - { |
|
139 | - return [ |
|
140 | - 'ramData' => (array)$this->getRawData(), |
|
141 | - 'jsonEncoded' => json_decode($this->getRawData()) |
|
142 | - ]; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Parse raw data |
|
147 | - * |
|
148 | - * @return Payload |
|
149 | - * @throws BadSignatureException |
|
150 | - * @throws \Exception |
|
151 | - */ |
|
152 | - public function parse(): Payload |
|
153 | - { |
|
154 | - /** Check signature from header */ |
|
155 | - if (!$this->_checkSignature()) { |
|
156 | - throw new BadSignatureException('Hook secret does not match.'); |
|
157 | - } |
|
158 | - |
|
159 | - /** Get data from different locations according to content-type */ |
|
160 | - switch ($_SERVER['CONTENT_TYPE']) { |
|
161 | - case 'application/json': |
|
162 | - $data = $this->getRawData(); |
|
163 | - break; |
|
164 | - |
|
165 | - case 'application/x-www-form-urlencoded': |
|
166 | - $data = $_POST['payload']; |
|
167 | - break; |
|
168 | - |
|
169 | - default: |
|
170 | - throw new \Exception('Unsupported content type: "' . $_SERVER['CONTENT_TYPE'] . '"'); |
|
171 | - } |
|
172 | - $this->setParsedData($data); |
|
173 | - |
|
174 | - return $this; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Check X-Hub-Signature |
|
179 | - * |
|
180 | - * @throws BadSignatureException |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - private function _checkSignature(): bool |
|
184 | - { |
|
185 | - if (null !== $this->secret) { |
|
186 | - if ($this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE')) { |
|
187 | - /** |
|
188 | - * Split signature into algorithm and hash |
|
189 | - * |
|
190 | - * @link http://isometriks.com/verify-github-webhooks-with-php |
|
191 | - */ |
|
192 | - list(, $hash) = explode('=', $this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE'), 2); |
|
193 | - |
|
194 | - return $this->secret == $hash; |
|
195 | - } |
|
196 | - |
|
197 | - throw new BadSignatureException('HTTP header "X-Hub-Signature" is missing.'); |
|
198 | - } |
|
199 | - |
|
200 | - return true; |
|
201 | - } |
|
16 | + /** Protected properties */ |
|
17 | + protected $webHook; |
|
18 | + protected $secret = null; |
|
19 | + protected $rawData; |
|
20 | + protected $parsedData; |
|
21 | + |
|
22 | + /** |
|
23 | + * Constructor, pass a WebHook object |
|
24 | + * |
|
25 | + * @param WebHook $webHook |
|
26 | + */ |
|
27 | + public function __construct(WebHook $webHook) |
|
28 | + { |
|
29 | + $this->setWebHook($webHook); |
|
30 | + $this->setRawData($webHook->getRequest()->getContent()); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Get webHook |
|
35 | + * |
|
36 | + * @return null|WebHook |
|
37 | + */ |
|
38 | + public function getWebHook() |
|
39 | + { |
|
40 | + return $this->webHook; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Set webHook |
|
45 | + * |
|
46 | + * @param mixed $webHook |
|
47 | + * |
|
48 | + * @return Payload |
|
49 | + */ |
|
50 | + public function setWebHook($webHook): Payload |
|
51 | + { |
|
52 | + $this->webHook = $webHook; |
|
53 | + |
|
54 | + return $this; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Set secret, encode this secret with Hmac, SHA1 method |
|
59 | + * |
|
60 | + * @param string $secret |
|
61 | + * |
|
62 | + * @return Payload |
|
63 | + */ |
|
64 | + public function setSecret(string $secret): Payload |
|
65 | + { |
|
66 | + $this->secret = hash_hmac('sha1', $this->rawData, $secret); |
|
67 | + |
|
68 | + return $this; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Get secret |
|
73 | + * |
|
74 | + * @return null|string |
|
75 | + */ |
|
76 | + public function getSecret() |
|
77 | + { |
|
78 | + return $this->secret; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Get rawData |
|
83 | + * |
|
84 | + * @return resource|string |
|
85 | + */ |
|
86 | + public function getRawData() |
|
87 | + { |
|
88 | + return $this->rawData; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Set rawData |
|
93 | + * |
|
94 | + * @param resource|string $rawData |
|
95 | + * |
|
96 | + * @return Payload |
|
97 | + */ |
|
98 | + public function setRawData($rawData): Payload |
|
99 | + { |
|
100 | + $this->rawData = $rawData; |
|
101 | + |
|
102 | + return $this; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Get parsedData |
|
107 | + * |
|
108 | + * @return mixed |
|
109 | + */ |
|
110 | + public function getData() |
|
111 | + { |
|
112 | + return $this->parsedData; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Set parsedData |
|
117 | + * |
|
118 | + * @param mixed $parsedData |
|
119 | + * |
|
120 | + * @return Payload |
|
121 | + */ |
|
122 | + protected function setParsedData($parsedData): Payload |
|
123 | + { |
|
124 | + $data = json_decode($parsedData); |
|
125 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
126 | + $this->parsedData = $data; |
|
127 | + } |
|
128 | + |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Debugger |
|
134 | + * |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function __debugInfo(): array |
|
138 | + { |
|
139 | + return [ |
|
140 | + 'ramData' => (array)$this->getRawData(), |
|
141 | + 'jsonEncoded' => json_decode($this->getRawData()) |
|
142 | + ]; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Parse raw data |
|
147 | + * |
|
148 | + * @return Payload |
|
149 | + * @throws BadSignatureException |
|
150 | + * @throws \Exception |
|
151 | + */ |
|
152 | + public function parse(): Payload |
|
153 | + { |
|
154 | + /** Check signature from header */ |
|
155 | + if (!$this->_checkSignature()) { |
|
156 | + throw new BadSignatureException('Hook secret does not match.'); |
|
157 | + } |
|
158 | + |
|
159 | + /** Get data from different locations according to content-type */ |
|
160 | + switch ($_SERVER['CONTENT_TYPE']) { |
|
161 | + case 'application/json': |
|
162 | + $data = $this->getRawData(); |
|
163 | + break; |
|
164 | + |
|
165 | + case 'application/x-www-form-urlencoded': |
|
166 | + $data = $_POST['payload']; |
|
167 | + break; |
|
168 | + |
|
169 | + default: |
|
170 | + throw new \Exception('Unsupported content type: "' . $_SERVER['CONTENT_TYPE'] . '"'); |
|
171 | + } |
|
172 | + $this->setParsedData($data); |
|
173 | + |
|
174 | + return $this; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Check X-Hub-Signature |
|
179 | + * |
|
180 | + * @throws BadSignatureException |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + private function _checkSignature(): bool |
|
184 | + { |
|
185 | + if (null !== $this->secret) { |
|
186 | + if ($this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE')) { |
|
187 | + /** |
|
188 | + * Split signature into algorithm and hash |
|
189 | + * |
|
190 | + * @link http://isometriks.com/verify-github-webhooks-with-php |
|
191 | + */ |
|
192 | + list(, $hash) = explode('=', $this->getWebHook()->getRequest()->server->get('HTTP_X_HUB_SIGNATURE'), 2); |
|
193 | + |
|
194 | + return $this->secret == $hash; |
|
195 | + } |
|
196 | + |
|
197 | + throw new BadSignatureException('HTTP header "X-Hub-Signature" is missing.'); |
|
198 | + } |
|
199 | + |
|
200 | + return true; |
|
201 | + } |
|
202 | 202 | } |
203 | 203 | \ No newline at end of file |
@@ -13,253 +13,253 @@ |
||
13 | 13 | class Gists extends AbstractReceiver |
14 | 14 | { |
15 | 15 | |
16 | - /** Available sub-Receiver */ |
|
17 | - const COMMENTS = 'Comments'; |
|
16 | + /** Available sub-Receiver */ |
|
17 | + const COMMENTS = 'Comments'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * List a user's gists |
|
21 | - * |
|
22 | - * @link https://developer.github.com/v3/gists/#list-a-users-gists |
|
23 | - * |
|
24 | - * @param string $username |
|
25 | - * @param string $since |
|
26 | - * |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function listGists(string $username = null, string $since = '1970-01-01'): array |
|
30 | - { |
|
31 | - $url = '/gists'; |
|
32 | - if (null !== $username) { |
|
33 | - $url = '/users/:username/gists'; |
|
34 | - } |
|
19 | + /** |
|
20 | + * List a user's gists |
|
21 | + * |
|
22 | + * @link https://developer.github.com/v3/gists/#list-a-users-gists |
|
23 | + * |
|
24 | + * @param string $username |
|
25 | + * @param string $since |
|
26 | + * |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function listGists(string $username = null, string $since = '1970-01-01'): array |
|
30 | + { |
|
31 | + $url = '/gists'; |
|
32 | + if (null !== $username) { |
|
33 | + $url = '/users/:username/gists'; |
|
34 | + } |
|
35 | 35 | |
36 | - return $this->getApi()->request($this->getApi()->sprintf(':url?:arg', $url, $username, |
|
37 | - http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
38 | - } |
|
36 | + return $this->getApi()->request($this->getApi()->sprintf(':url?:arg', $url, $username, |
|
37 | + http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * List all public gists: |
|
42 | - * |
|
43 | - * @link https://developer.github.com/v3/gists/#list-all-public-gists |
|
44 | - * |
|
45 | - * @param string $since |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function listPublicGists(string $since = '1970-01-01'): array |
|
50 | - { |
|
51 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/public?:arg', |
|
52 | - http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
53 | - } |
|
40 | + /** |
|
41 | + * List all public gists: |
|
42 | + * |
|
43 | + * @link https://developer.github.com/v3/gists/#list-all-public-gists |
|
44 | + * |
|
45 | + * @param string $since |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function listPublicGists(string $since = '1970-01-01'): array |
|
50 | + { |
|
51 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/public?:arg', |
|
52 | + http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * List the authenticated user’s starred gists |
|
57 | - * |
|
58 | - * @link https://developer.github.com/v3/gists/#list-starred-gists |
|
59 | - * |
|
60 | - * @param string $since |
|
61 | - * |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function listUsersStarredGists(string $since = '1970-01-01'): array |
|
65 | - { |
|
66 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/starred?:arg', |
|
67 | - http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
68 | - } |
|
55 | + /** |
|
56 | + * List the authenticated user’s starred gists |
|
57 | + * |
|
58 | + * @link https://developer.github.com/v3/gists/#list-starred-gists |
|
59 | + * |
|
60 | + * @param string $since |
|
61 | + * |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function listUsersStarredGists(string $since = '1970-01-01'): array |
|
65 | + { |
|
66 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/starred?:arg', |
|
67 | + http_build_query(['since' => (new DateTime($since))->format(DateTime::ATOM)]))); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get a single gist |
|
72 | - * |
|
73 | - * @link https://developer.github.com/v3/gists/#get-a-single-gist |
|
74 | - * |
|
75 | - * @param string $id |
|
76 | - * |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function getGist(string $id): array |
|
80 | - { |
|
81 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id)); |
|
82 | - } |
|
70 | + /** |
|
71 | + * Get a single gist |
|
72 | + * |
|
73 | + * @link https://developer.github.com/v3/gists/#get-a-single-gist |
|
74 | + * |
|
75 | + * @param string $id |
|
76 | + * |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function getGist(string $id): array |
|
80 | + { |
|
81 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id)); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get a specific revision of a gist |
|
86 | - * |
|
87 | - * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist |
|
88 | - * |
|
89 | - * @param string $id |
|
90 | - * @param string $sha |
|
91 | - * |
|
92 | - * @return array |
|
93 | - * @throws \Exception |
|
94 | - */ |
|
95 | - public function getGistRevision(string $id, string $sha): array |
|
96 | - { |
|
97 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/:sha', $id, $sha)); |
|
98 | - } |
|
84 | + /** |
|
85 | + * Get a specific revision of a gist |
|
86 | + * |
|
87 | + * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist |
|
88 | + * |
|
89 | + * @param string $id |
|
90 | + * @param string $sha |
|
91 | + * |
|
92 | + * @return array |
|
93 | + * @throws \Exception |
|
94 | + */ |
|
95 | + public function getGistRevision(string $id, string $sha): array |
|
96 | + { |
|
97 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/:sha', $id, $sha)); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Create a gist |
|
102 | - * |
|
103 | - * @link https://developer.github.com/v3/gists/#create-a-gist |
|
104 | - * |
|
105 | - * @param array $files |
|
106 | - * @param string $description |
|
107 | - * @param bool $public |
|
108 | - * |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function createGist(array $files, string $description = null, bool $public = false): array |
|
112 | - { |
|
113 | - return $this->getApi()->request($this->getApi()->sprintf('/gists'), Request::METHOD_POST, [ |
|
114 | - 'files' => $files, |
|
115 | - 'description' => $description, |
|
116 | - 'public' => $public |
|
117 | - ]); |
|
118 | - } |
|
100 | + /** |
|
101 | + * Create a gist |
|
102 | + * |
|
103 | + * @link https://developer.github.com/v3/gists/#create-a-gist |
|
104 | + * |
|
105 | + * @param array $files |
|
106 | + * @param string $description |
|
107 | + * @param bool $public |
|
108 | + * |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function createGist(array $files, string $description = null, bool $public = false): array |
|
112 | + { |
|
113 | + return $this->getApi()->request($this->getApi()->sprintf('/gists'), Request::METHOD_POST, [ |
|
114 | + 'files' => $files, |
|
115 | + 'description' => $description, |
|
116 | + 'public' => $public |
|
117 | + ]); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Edit a gist |
|
122 | - * |
|
123 | - * @link https://developer.github.com/v3/gists/#edit-a-gist |
|
124 | - * |
|
125 | - * @param string $id |
|
126 | - * @param string $description |
|
127 | - * @param array $files |
|
128 | - * @param string $content |
|
129 | - * @param string $filename |
|
130 | - * |
|
131 | - * @return array |
|
132 | - */ |
|
133 | - public function editGist(string $id, string $description = '', array $files = [], string $content = '', |
|
134 | - string $filename = ''): array |
|
135 | - { |
|
136 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_PATCH, [ |
|
137 | - 'description' => $description, |
|
138 | - 'files' => $files, |
|
139 | - 'content' => $content, |
|
140 | - 'filename' => $filename |
|
141 | - ]); |
|
142 | - } |
|
120 | + /** |
|
121 | + * Edit a gist |
|
122 | + * |
|
123 | + * @link https://developer.github.com/v3/gists/#edit-a-gist |
|
124 | + * |
|
125 | + * @param string $id |
|
126 | + * @param string $description |
|
127 | + * @param array $files |
|
128 | + * @param string $content |
|
129 | + * @param string $filename |
|
130 | + * |
|
131 | + * @return array |
|
132 | + */ |
|
133 | + public function editGist(string $id, string $description = '', array $files = [], string $content = '', |
|
134 | + string $filename = ''): array |
|
135 | + { |
|
136 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_PATCH, [ |
|
137 | + 'description' => $description, |
|
138 | + 'files' => $files, |
|
139 | + 'content' => $content, |
|
140 | + 'filename' => $filename |
|
141 | + ]); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * List gist commits |
|
146 | - * |
|
147 | - * @link https://developer.github.com/v3/gists/#list-gist-commits |
|
148 | - * |
|
149 | - * @param string $id |
|
150 | - * |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function listGistsCommits(string $id): array |
|
154 | - { |
|
155 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/commits', $id)); |
|
156 | - } |
|
144 | + /** |
|
145 | + * List gist commits |
|
146 | + * |
|
147 | + * @link https://developer.github.com/v3/gists/#list-gist-commits |
|
148 | + * |
|
149 | + * @param string $id |
|
150 | + * |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function listGistsCommits(string $id): array |
|
154 | + { |
|
155 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/commits', $id)); |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Star a gist |
|
160 | - * |
|
161 | - * @link https://developer.github.com/v3/gists/#star-a-gist |
|
162 | - * |
|
163 | - * @param string $id |
|
164 | - * |
|
165 | - * @return bool |
|
166 | - */ |
|
167 | - public function starGist(string $id): bool |
|
168 | - { |
|
169 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_PUT); |
|
158 | + /** |
|
159 | + * Star a gist |
|
160 | + * |
|
161 | + * @link https://developer.github.com/v3/gists/#star-a-gist |
|
162 | + * |
|
163 | + * @param string $id |
|
164 | + * |
|
165 | + * @return bool |
|
166 | + */ |
|
167 | + public function starGist(string $id): bool |
|
168 | + { |
|
169 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_PUT); |
|
170 | 170 | |
171 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
172 | - return true; |
|
173 | - } |
|
171 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
172 | + return true; |
|
173 | + } |
|
174 | 174 | |
175 | - return false; |
|
176 | - } |
|
175 | + return false; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Unstar a gist |
|
180 | - * |
|
181 | - * @link https://developer.github.com/v3/gists/#unstar-a-gist |
|
182 | - * |
|
183 | - * @param string $id |
|
184 | - * |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function unStarGist(string $id): bool |
|
188 | - { |
|
189 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_DELETE); |
|
178 | + /** |
|
179 | + * Unstar a gist |
|
180 | + * |
|
181 | + * @link https://developer.github.com/v3/gists/#unstar-a-gist |
|
182 | + * |
|
183 | + * @param string $id |
|
184 | + * |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function unStarGist(string $id): bool |
|
188 | + { |
|
189 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id), Request::METHOD_DELETE); |
|
190 | 190 | |
191 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
192 | - return true; |
|
193 | - } |
|
191 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
192 | + return true; |
|
193 | + } |
|
194 | 194 | |
195 | - return false; |
|
196 | - } |
|
195 | + return false; |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Check if a gist is starred |
|
200 | - * |
|
201 | - * @link https://developer.github.com/v3/gists/#check-if-a-gist-is-starred |
|
202 | - * |
|
203 | - * @param string $id |
|
204 | - * |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function checkGistIsStarred(string $id): bool |
|
208 | - { |
|
209 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id)); |
|
198 | + /** |
|
199 | + * Check if a gist is starred |
|
200 | + * |
|
201 | + * @link https://developer.github.com/v3/gists/#check-if-a-gist-is-starred |
|
202 | + * |
|
203 | + * @param string $id |
|
204 | + * |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function checkGistIsStarred(string $id): bool |
|
208 | + { |
|
209 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id/star', $id)); |
|
210 | 210 | |
211 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
212 | - return true; |
|
213 | - } |
|
211 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
212 | + return true; |
|
213 | + } |
|
214 | 214 | |
215 | - return false; |
|
216 | - } |
|
215 | + return false; |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Fork a gist |
|
220 | - * |
|
221 | - * @link https://developer.github.com/v3/gists/#fork-a-gist |
|
222 | - * |
|
223 | - * @param string $id |
|
224 | - * |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function forkGist(string $id): array |
|
228 | - { |
|
229 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id), Request::METHOD_POST); |
|
230 | - } |
|
218 | + /** |
|
219 | + * Fork a gist |
|
220 | + * |
|
221 | + * @link https://developer.github.com/v3/gists/#fork-a-gist |
|
222 | + * |
|
223 | + * @param string $id |
|
224 | + * |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function forkGist(string $id): array |
|
228 | + { |
|
229 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id), Request::METHOD_POST); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * List gist forks |
|
234 | - * |
|
235 | - * @link https://developer.github.com/v3/gists/#list-gist-forks |
|
236 | - * |
|
237 | - * @param string $id |
|
238 | - * |
|
239 | - * @return array |
|
240 | - */ |
|
241 | - public function listGistForks(string $id): array |
|
242 | - { |
|
243 | - return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id)); |
|
244 | - } |
|
232 | + /** |
|
233 | + * List gist forks |
|
234 | + * |
|
235 | + * @link https://developer.github.com/v3/gists/#list-gist-forks |
|
236 | + * |
|
237 | + * @param string $id |
|
238 | + * |
|
239 | + * @return array |
|
240 | + */ |
|
241 | + public function listGistForks(string $id): array |
|
242 | + { |
|
243 | + return $this->getApi()->request($this->getApi()->sprintf('/gists/:id/forks', $id)); |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Delete a gist |
|
248 | - * |
|
249 | - * @link https://developer.github.com/v3/gists/#delete-a-gist |
|
250 | - * |
|
251 | - * @param string $id |
|
252 | - * |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - public function deleteGist(string $id): bool |
|
256 | - { |
|
257 | - $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_DELETE); |
|
246 | + /** |
|
247 | + * Delete a gist |
|
248 | + * |
|
249 | + * @link https://developer.github.com/v3/gists/#delete-a-gist |
|
250 | + * |
|
251 | + * @param string $id |
|
252 | + * |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + public function deleteGist(string $id): bool |
|
256 | + { |
|
257 | + $this->getApi()->request($this->getApi()->sprintf('/gists/:id', $id), Request::METHOD_DELETE); |
|
258 | 258 | |
259 | - if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
260 | - return true; |
|
261 | - } |
|
259 | + if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
|
260 | + return true; |
|
261 | + } |
|
262 | 262 | |
263 | - return false; |
|
264 | - } |
|
263 | + return false; |
|
264 | + } |
|
265 | 265 | } |
266 | 266 | \ 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 AbstractTest |
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 |
@@ -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\AbstractTest |
|
5 | + Client, Receiver\Gists, Tests\AbstractTest |
|
6 | 6 | }; |
7 | 7 | |
8 | 8 | /** |
@@ -12,236 +12,236 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GistsTest extends AbstractTest |
14 | 14 | { |
15 | - const PUBLIC_GIST = '76e253825bb3c6c084cf31f92997eb72'; |
|
16 | - |
|
17 | - /** @var Gists */ |
|
18 | - protected $gists; |
|
19 | - |
|
20 | - /** |
|
21 | - * GistsTest constructor. |
|
22 | - * |
|
23 | - * @param null $name |
|
24 | - * @param array $data |
|
25 | - * @param string $dataName |
|
26 | - */ |
|
27 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
28 | - { |
|
29 | - parent::__construct($name, $data, $dataName); |
|
30 | - |
|
31 | - // Gists |
|
32 | - $this->gists = $this->client->getReceiver(Client::GISTS); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Test list gists of current users |
|
37 | - */ |
|
38 | - public function testListGists() |
|
39 | - { |
|
40 | - $gists = $this->gists->listGists(); |
|
41 | - if (!empty($gists)) { |
|
42 | - $gist = array_pop($gists); |
|
43 | - |
|
44 | - $this->assertArrayHasKey('url', $gist); |
|
45 | - $this->assertArrayHasKey('files', $gist); |
|
46 | - $this->assertArrayHasKey('comments', $gist); |
|
47 | - $this->assertArrayHasKey('created_at', $gist); |
|
48 | - $this->assertArrayHasKey('updated_at', $gist); |
|
49 | - $this->assertArrayHasKey('user', $gist); |
|
50 | - } |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Test list public gists |
|
55 | - */ |
|
56 | - public function testPublicListGists() |
|
57 | - { |
|
58 | - $gists = $this->gists->listPublicGists(); |
|
59 | - if (!empty($gists)) { |
|
60 | - $gist = array_pop($gists); |
|
61 | - |
|
62 | - $this->assertArrayHasKey('url', $gist); |
|
63 | - $this->assertArrayHasKey('files', $gist); |
|
64 | - $this->assertArrayHasKey('comments', $gist); |
|
65 | - $this->assertArrayHasKey('created_at', $gist); |
|
66 | - $this->assertArrayHasKey('updated_at', $gist); |
|
67 | - $this->assertArrayHasKey('user', $gist); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Test list user's starred gists |
|
73 | - */ |
|
74 | - public function testListUsersStarredGists() |
|
75 | - { |
|
76 | - $gists = $this->gists->listUsersStarredGists(); |
|
77 | - if (!empty($gists)) { |
|
78 | - $gist = array_pop($gists); |
|
79 | - |
|
80 | - $this->assertArrayHasKey('url', $gist); |
|
81 | - $this->assertArrayHasKey('files', $gist); |
|
82 | - $this->assertArrayHasKey('comments', $gist); |
|
83 | - $this->assertArrayHasKey('created_at', $gist); |
|
84 | - $this->assertArrayHasKey('updated_at', $gist); |
|
85 | - $this->assertArrayHasKey('user', $gist); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Test getting gist by ID |
|
91 | - */ |
|
92 | - public function testGetGistById() |
|
93 | - { |
|
94 | - $gist = $this->gists->getGist(1); |
|
95 | - |
|
96 | - $this->assertArrayHasKey('url', $gist); |
|
97 | - $this->assertArrayHasKey('files', $gist); |
|
98 | - $this->assertArrayHasKey('comments', $gist); |
|
99 | - $this->assertArrayHasKey('created_at', $gist); |
|
100 | - $this->assertArrayHasKey('updated_at', $gist); |
|
101 | - $this->assertArrayHasKey('user', $gist); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Test creating a new gist |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function testCreateGist(): string |
|
110 | - { |
|
111 | - $gist = $this->gists->createGist([ |
|
112 | - md5('phpunit-testing') . '.txt' => [ |
|
113 | - 'content' => 'String file contents' |
|
114 | - ] |
|
115 | - ], 'the description for this gist', true); |
|
116 | - |
|
117 | - $this->assertArrayHasKey('url', $gist); |
|
118 | - $this->assertArrayHasKey('files', $gist); |
|
119 | - $this->assertArrayHasKey('comments', $gist); |
|
120 | - $this->assertArrayHasKey('created_at', $gist); |
|
121 | - $this->assertArrayHasKey('updated_at', $gist); |
|
122 | - $this->assertArrayHasKey('user', $gist); |
|
123 | - |
|
124 | - return $gist['id']; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Test updating an existing gist |
|
129 | - * |
|
130 | - * @depends testCreateGist |
|
131 | - * |
|
132 | - * @param string $gistId |
|
133 | - */ |
|
134 | - public function testUpdateGist(string $gistId) |
|
135 | - { |
|
136 | - $gist = $this->gists->editGist($gistId, 'the description UPDATED for this gist', [ |
|
137 | - md5('phpunit-testing') . '.txt' => [ |
|
138 | - 'content' => 'String file contents' |
|
139 | - ] |
|
140 | - ], 'content', 'renamed-file.name'); |
|
141 | - |
|
142 | - $this->assertEquals('the description UPDATED for this gist', $gist['description']); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Test list commits of a gist |
|
147 | - * |
|
148 | - * @depends testCreateGist |
|
149 | - * |
|
150 | - * @param string $gistId |
|
151 | - */ |
|
152 | - public function testListGistsCommit(string $gistId) |
|
153 | - { |
|
154 | - $gists = $this->gists->listGistsCommits($gistId); |
|
155 | - $gist = array_pop($gists); |
|
156 | - |
|
157 | - $this->assertArrayHasKey('user', $gist); |
|
158 | - $this->assertArrayHasKey('version', $gist); |
|
159 | - $this->assertArrayHasKey('committed_at', $gist); |
|
160 | - $this->assertArrayHasKey('change_status', $gist); |
|
161 | - $this->assertArrayHasKey('url', $gist); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Test starring a gist |
|
166 | - * |
|
167 | - * @depends testCreateGist |
|
168 | - * |
|
169 | - * @param string $gistId |
|
170 | - */ |
|
171 | - public function testStarGist(string $gistId) |
|
172 | - { |
|
173 | - $this->assertTrue($this->gists->starGist($gistId)); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Test gist is starred |
|
178 | - * |
|
179 | - * @depends testCreateGist |
|
180 | - * |
|
181 | - * @param string $gistId |
|
182 | - */ |
|
183 | - public function testGistIsStarred(string $gistId) |
|
184 | - { |
|
185 | - $this->assertTrue($this->gists->checkGistIsStarred($gistId)); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Test unstar a gist |
|
190 | - * |
|
191 | - * @depends testCreateGist |
|
192 | - * |
|
193 | - * @param string $gistId |
|
194 | - */ |
|
195 | - public function testUnStarGist(string $gistId) |
|
196 | - { |
|
197 | - $this->assertTrue($this->gists->unStarGist($gistId)); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Test fork a public gist |
|
202 | - */ |
|
203 | - public function testForkGist() |
|
204 | - { |
|
205 | - $gist = $this->gists->forkGist(self::PUBLIC_GIST); |
|
206 | - |
|
207 | - $this->assertArrayHasKey('forks_url', $gist); |
|
208 | - |
|
209 | - return $gist['id']; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Test list forks of a specific gist |
|
214 | - */ |
|
215 | - public function testListGistForks() |
|
216 | - { |
|
217 | - $gists = $this->gists->listGistForks(self::PUBLIC_GIST); |
|
218 | - $gist = array_pop($gists); |
|
219 | - |
|
220 | - $this->assertArrayHasKey('url', $gist); |
|
221 | - $this->assertArrayHasKey('id', $gist); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Test deleting an existing gist |
|
226 | - * |
|
227 | - * @depends testCreateGist |
|
228 | - * |
|
229 | - * @param string $gistId |
|
230 | - */ |
|
231 | - public function testDeleteGist(string $gistId) |
|
232 | - { |
|
233 | - $this->assertTrue($this->gists->deleteGist($gistId)); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Test deleting a forked gist |
|
238 | - * |
|
239 | - * @depends testForkGist |
|
240 | - * |
|
241 | - * @param string $gistId |
|
242 | - */ |
|
243 | - public function testDeleteForkedGist(string $gistId) |
|
244 | - { |
|
245 | - $this->assertTrue($this->gists->deleteGist($gistId)); |
|
246 | - } |
|
15 | + const PUBLIC_GIST = '76e253825bb3c6c084cf31f92997eb72'; |
|
16 | + |
|
17 | + /** @var Gists */ |
|
18 | + protected $gists; |
|
19 | + |
|
20 | + /** |
|
21 | + * GistsTest constructor. |
|
22 | + * |
|
23 | + * @param null $name |
|
24 | + * @param array $data |
|
25 | + * @param string $dataName |
|
26 | + */ |
|
27 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
28 | + { |
|
29 | + parent::__construct($name, $data, $dataName); |
|
30 | + |
|
31 | + // Gists |
|
32 | + $this->gists = $this->client->getReceiver(Client::GISTS); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Test list gists of current users |
|
37 | + */ |
|
38 | + public function testListGists() |
|
39 | + { |
|
40 | + $gists = $this->gists->listGists(); |
|
41 | + if (!empty($gists)) { |
|
42 | + $gist = array_pop($gists); |
|
43 | + |
|
44 | + $this->assertArrayHasKey('url', $gist); |
|
45 | + $this->assertArrayHasKey('files', $gist); |
|
46 | + $this->assertArrayHasKey('comments', $gist); |
|
47 | + $this->assertArrayHasKey('created_at', $gist); |
|
48 | + $this->assertArrayHasKey('updated_at', $gist); |
|
49 | + $this->assertArrayHasKey('user', $gist); |
|
50 | + } |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Test list public gists |
|
55 | + */ |
|
56 | + public function testPublicListGists() |
|
57 | + { |
|
58 | + $gists = $this->gists->listPublicGists(); |
|
59 | + if (!empty($gists)) { |
|
60 | + $gist = array_pop($gists); |
|
61 | + |
|
62 | + $this->assertArrayHasKey('url', $gist); |
|
63 | + $this->assertArrayHasKey('files', $gist); |
|
64 | + $this->assertArrayHasKey('comments', $gist); |
|
65 | + $this->assertArrayHasKey('created_at', $gist); |
|
66 | + $this->assertArrayHasKey('updated_at', $gist); |
|
67 | + $this->assertArrayHasKey('user', $gist); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Test list user's starred gists |
|
73 | + */ |
|
74 | + public function testListUsersStarredGists() |
|
75 | + { |
|
76 | + $gists = $this->gists->listUsersStarredGists(); |
|
77 | + if (!empty($gists)) { |
|
78 | + $gist = array_pop($gists); |
|
79 | + |
|
80 | + $this->assertArrayHasKey('url', $gist); |
|
81 | + $this->assertArrayHasKey('files', $gist); |
|
82 | + $this->assertArrayHasKey('comments', $gist); |
|
83 | + $this->assertArrayHasKey('created_at', $gist); |
|
84 | + $this->assertArrayHasKey('updated_at', $gist); |
|
85 | + $this->assertArrayHasKey('user', $gist); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Test getting gist by ID |
|
91 | + */ |
|
92 | + public function testGetGistById() |
|
93 | + { |
|
94 | + $gist = $this->gists->getGist(1); |
|
95 | + |
|
96 | + $this->assertArrayHasKey('url', $gist); |
|
97 | + $this->assertArrayHasKey('files', $gist); |
|
98 | + $this->assertArrayHasKey('comments', $gist); |
|
99 | + $this->assertArrayHasKey('created_at', $gist); |
|
100 | + $this->assertArrayHasKey('updated_at', $gist); |
|
101 | + $this->assertArrayHasKey('user', $gist); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Test creating a new gist |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function testCreateGist(): string |
|
110 | + { |
|
111 | + $gist = $this->gists->createGist([ |
|
112 | + md5('phpunit-testing') . '.txt' => [ |
|
113 | + 'content' => 'String file contents' |
|
114 | + ] |
|
115 | + ], 'the description for this gist', true); |
|
116 | + |
|
117 | + $this->assertArrayHasKey('url', $gist); |
|
118 | + $this->assertArrayHasKey('files', $gist); |
|
119 | + $this->assertArrayHasKey('comments', $gist); |
|
120 | + $this->assertArrayHasKey('created_at', $gist); |
|
121 | + $this->assertArrayHasKey('updated_at', $gist); |
|
122 | + $this->assertArrayHasKey('user', $gist); |
|
123 | + |
|
124 | + return $gist['id']; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Test updating an existing gist |
|
129 | + * |
|
130 | + * @depends testCreateGist |
|
131 | + * |
|
132 | + * @param string $gistId |
|
133 | + */ |
|
134 | + public function testUpdateGist(string $gistId) |
|
135 | + { |
|
136 | + $gist = $this->gists->editGist($gistId, 'the description UPDATED for this gist', [ |
|
137 | + md5('phpunit-testing') . '.txt' => [ |
|
138 | + 'content' => 'String file contents' |
|
139 | + ] |
|
140 | + ], 'content', 'renamed-file.name'); |
|
141 | + |
|
142 | + $this->assertEquals('the description UPDATED for this gist', $gist['description']); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Test list commits of a gist |
|
147 | + * |
|
148 | + * @depends testCreateGist |
|
149 | + * |
|
150 | + * @param string $gistId |
|
151 | + */ |
|
152 | + public function testListGistsCommit(string $gistId) |
|
153 | + { |
|
154 | + $gists = $this->gists->listGistsCommits($gistId); |
|
155 | + $gist = array_pop($gists); |
|
156 | + |
|
157 | + $this->assertArrayHasKey('user', $gist); |
|
158 | + $this->assertArrayHasKey('version', $gist); |
|
159 | + $this->assertArrayHasKey('committed_at', $gist); |
|
160 | + $this->assertArrayHasKey('change_status', $gist); |
|
161 | + $this->assertArrayHasKey('url', $gist); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Test starring a gist |
|
166 | + * |
|
167 | + * @depends testCreateGist |
|
168 | + * |
|
169 | + * @param string $gistId |
|
170 | + */ |
|
171 | + public function testStarGist(string $gistId) |
|
172 | + { |
|
173 | + $this->assertTrue($this->gists->starGist($gistId)); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Test gist is starred |
|
178 | + * |
|
179 | + * @depends testCreateGist |
|
180 | + * |
|
181 | + * @param string $gistId |
|
182 | + */ |
|
183 | + public function testGistIsStarred(string $gistId) |
|
184 | + { |
|
185 | + $this->assertTrue($this->gists->checkGistIsStarred($gistId)); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Test unstar a gist |
|
190 | + * |
|
191 | + * @depends testCreateGist |
|
192 | + * |
|
193 | + * @param string $gistId |
|
194 | + */ |
|
195 | + public function testUnStarGist(string $gistId) |
|
196 | + { |
|
197 | + $this->assertTrue($this->gists->unStarGist($gistId)); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Test fork a public gist |
|
202 | + */ |
|
203 | + public function testForkGist() |
|
204 | + { |
|
205 | + $gist = $this->gists->forkGist(self::PUBLIC_GIST); |
|
206 | + |
|
207 | + $this->assertArrayHasKey('forks_url', $gist); |
|
208 | + |
|
209 | + return $gist['id']; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Test list forks of a specific gist |
|
214 | + */ |
|
215 | + public function testListGistForks() |
|
216 | + { |
|
217 | + $gists = $this->gists->listGistForks(self::PUBLIC_GIST); |
|
218 | + $gist = array_pop($gists); |
|
219 | + |
|
220 | + $this->assertArrayHasKey('url', $gist); |
|
221 | + $this->assertArrayHasKey('id', $gist); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Test deleting an existing gist |
|
226 | + * |
|
227 | + * @depends testCreateGist |
|
228 | + * |
|
229 | + * @param string $gistId |
|
230 | + */ |
|
231 | + public function testDeleteGist(string $gistId) |
|
232 | + { |
|
233 | + $this->assertTrue($this->gists->deleteGist($gistId)); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Test deleting a forked gist |
|
238 | + * |
|
239 | + * @depends testForkGist |
|
240 | + * |
|
241 | + * @param string $gistId |
|
242 | + */ |
|
243 | + public function testDeleteForkedGist(string $gistId) |
|
244 | + { |
|
245 | + $this->assertTrue($this->gists->deleteGist($gistId)); |
|
246 | + } |
|
247 | 247 | } |
248 | 248 | \ 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\AbstractTest |
|
5 | + Client, Receiver\Miscellaneous, Tests\AbstractTest |
|
6 | 6 | }; |
7 | 7 | |
8 | 8 | /** |
@@ -13,32 +13,32 @@ discard block |
||
13 | 13 | class MiscellaneousTest extends AbstractTest |
14 | 14 | { |
15 | 15 | |
16 | - /** @var Miscellaneous */ |
|
17 | - protected $miscellaneous; |
|
16 | + /** @var Miscellaneous */ |
|
17 | + protected $miscellaneous; |
|
18 | 18 | |
19 | - /** |
|
20 | - * MiscellaneousTest constructor. |
|
21 | - * |
|
22 | - * @param null $name |
|
23 | - * @param array $data |
|
24 | - * @param string $dataName |
|
25 | - */ |
|
26 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
27 | - { |
|
28 | - parent::__construct($name, $data, $dataName); |
|
19 | + /** |
|
20 | + * MiscellaneousTest constructor. |
|
21 | + * |
|
22 | + * @param null $name |
|
23 | + * @param array $data |
|
24 | + * @param string $dataName |
|
25 | + */ |
|
26 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
27 | + { |
|
28 | + parent::__construct($name, $data, $dataName); |
|
29 | 29 | |
30 | - // Miscellaneous |
|
31 | - $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); |
|
32 | - } |
|
30 | + // Miscellaneous |
|
31 | + $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Test list available Emojis |
|
36 | - */ |
|
37 | - public function testGetListEmojis() |
|
38 | - { |
|
39 | - /** @var Miscellaneous\Emojis $emojis */ |
|
40 | - $emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); |
|
34 | + /** |
|
35 | + * Test list available Emojis |
|
36 | + */ |
|
37 | + public function testGetListEmojis() |
|
38 | + { |
|
39 | + /** @var Miscellaneous\Emojis $emojis */ |
|
40 | + $emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); |
|
41 | 41 | |
42 | - $this->assertEquals(1508, count($emojis->get())); |
|
43 | - } |
|
42 | + $this->assertEquals(1508, count($emojis->get())); |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | \ No newline at end of file |
@@ -12,28 +12,28 @@ |
||
12 | 12 | abstract class AbstractTest extends TestCase |
13 | 13 | { |
14 | 14 | |
15 | - /** Authentication constants */ |
|
16 | - const USERNAME = 'githubapi-octocat'; |
|
17 | - const PASSWORD = 'S=p}g2E($L#T(K3x'; |
|
15 | + /** Authentication constants */ |
|
16 | + const USERNAME = 'githubapi-octocat'; |
|
17 | + const PASSWORD = 'S=p}g2E($L#T(K3x'; |
|
18 | 18 | |
19 | - /** @var Client */ |
|
20 | - protected $client; |
|
19 | + /** @var Client */ |
|
20 | + protected $client; |
|
21 | 21 | |
22 | - /** |
|
23 | - * AbstractTest constructor. |
|
24 | - * |
|
25 | - * @param null $name |
|
26 | - * @param array $data |
|
27 | - * @param string $dataName |
|
28 | - */ |
|
29 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
30 | - { |
|
31 | - // Create a client object |
|
32 | - $this->client = new Client(); |
|
22 | + /** |
|
23 | + * AbstractTest constructor. |
|
24 | + * |
|
25 | + * @param null $name |
|
26 | + * @param array $data |
|
27 | + * @param string $dataName |
|
28 | + */ |
|
29 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
30 | + { |
|
31 | + // Create a client object |
|
32 | + $this->client = new Client(); |
|
33 | 33 | |
34 | - // Set auth credentials |
|
35 | - $this->client->setHttpAuth(self::USERNAME, self::PASSWORD); |
|
34 | + // Set auth credentials |
|
35 | + $this->client->setHttpAuth(self::USERNAME, self::PASSWORD); |
|
36 | 36 | |
37 | - parent::__construct($name, $data, $dataName); |
|
38 | - } |
|
37 | + parent::__construct($name, $data, $dataName); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |