File tree Expand file tree Collapse file tree 5 files changed +108
-0
lines changed
test/Github/Tests/Api/Miscellaneous Expand file tree Collapse file tree 5 files changed +108
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ v3 APIs:
3434 * [ Code of conduct] ( miscellaneous/codeofconduct.md )
3535 * [ Emojis] ( miscellaneous/emojis.md )
3636 * [ Gitignore] ( miscellaneous/gitignore.md )
37+ * [ Licenses] ( miscellaneous/licenses.md )
3738 * [ Markdown] ( miscellaneous/markdown.md )
3839* [ Organization] ( organization.md )
3940 * [ Members] ( organization/members.md )
Original file line number Diff line number Diff line change 1+ ## Licenses API
2+ [ Back to the navigation] ( ../README.md )
3+
4+ ### Lists all licenses.
5+
6+ ``` php
7+ $licenses = $client->api('licenses')->all();
8+ ```
9+
10+ ### Get a license.
11+
12+ ``` php
13+ $license = $client->api('licenses')->show('gpl-2.0');
14+ ```
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Github \Api \Miscellaneous ;
4+
5+ use Github \Api \AbstractApi ;
6+
7+ class Licenses extends AbstractApi
8+ {
9+ /**
10+ * Lists all the licenses available on GitHub.
11+ *
12+ * @link https://developer.github.com/v3/licenses/
13+ *
14+ * @return array
15+ */
16+ public function all ()
17+ {
18+ return $ this ->get ('/licenses ' );
19+ }
20+
21+ /**
22+ * Get an individual license by its license key.
23+ *
24+ * @link https://developer.github.com/v3/licenses/#get-an-individual-license
25+ *
26+ * @param string $license
27+ *
28+ * @return array
29+ */
30+ public function show ($ license )
31+ {
32+ return $ this ->get ('/licenses/ ' .rawurlencode ($ license ));
33+ }
34+ }
Original file line number Diff line number Diff line change 2525 * @method Api\Enterprise enterprise()
2626 * @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
2727 * @method Api\Miscellaneous\Emojis emojis()
28+ * @method Api\Miscellaneous\Licenses licenses()
2829 * @method Api\GitData git()
2930 * @method Api\GitData gitData()
3031 * @method Api\Gists gist()
@@ -221,6 +222,10 @@ public function api($name)
221222 $ api = new Api \Markdown ($ this );
222223 break ;
223224
225+ case 'licenses ' :
226+ $ api = new Api \Miscellaneous \Licenses ($ this );
227+ break ;
228+
224229 case 'notification ' :
225230 case 'notifications ' :
226231 $ api = new Api \Notification ($ this );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Github \Tests \Api \Miscellaneous ;
4+
5+ use Github \Api \Miscellaneous \Licenses ;
6+ use Github \Tests \Api \TestCase ;
7+
8+ class LicensesTest extends TestCase
9+ {
10+ /**
11+ * @test
12+ */
13+ public function shouldGetAllLicenses ()
14+ {
15+ $ expectedArray = [
16+ ['key ' => 'mit ' ],
17+ ['key ' => 'apache-2.0 ' ],
18+ ];
19+
20+ $ api = $ this ->getApiMock ();
21+ $ api ->expects ($ this ->once ())
22+ ->method ('get ' )
23+ ->with ('/licenses ' )
24+ ->will ($ this ->returnValue ($ expectedArray ));
25+
26+ $ this ->assertEquals ($ expectedArray , $ api ->all ());
27+ }
28+
29+ /**
30+ * @test
31+ */
32+ public function shouldGetSingleLicenses ()
33+ {
34+ $ expectedArray = [
35+ 'key ' => 'gpl-2.0 ' ,
36+ ];
37+
38+ $ api = $ this ->getApiMock ();
39+ $ api ->expects ($ this ->once ())
40+ ->method ('get ' )
41+ ->with ('/licenses/gpl-2.0 ' )
42+ ->will ($ this ->returnValue ($ expectedArray ));
43+
44+ $ this ->assertEquals ($ expectedArray , $ api ->show ('gpl-2.0 ' ));
45+ }
46+
47+ /**
48+ * @return string
49+ */
50+ protected function getApiClass ()
51+ {
52+ return Licenses::class;
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments