@@ -11,8 +11,7 @@ class StatsTest extends TestCase
11
11
*/
12
12
public function shouldShowStats ()
13
13
{
14
- $ expectedJson = $ this ->getJson ();
15
- $ expectedArray = json_decode ($ expectedJson , true );
14
+ $ expectedArray = $ this ->getStatsData ();
16
15
17
16
$ api = $ this ->getApiMock ();
18
17
$ api ->expects ($ this ->once ())
@@ -23,9 +22,50 @@ public function shouldShowStats()
23
22
$ this ->assertEquals ($ expectedArray , $ api ->show ('all ' ));
24
23
}
25
24
26
- protected function getJson ()
25
+ /**
26
+ * @test
27
+ * @dataProvider getTypes
28
+ */
29
+ public function shouldShowStatsByType ($ type )
30
+ {
31
+ $ expectedArray = $ this ->getStatsData ($ type );
32
+
33
+ $ api = $ this ->getApiMock ();
34
+ $ api ->expects ($ this ->once ())
35
+ ->method ('get ' )
36
+ ->with (sprintf ('enterprise/stats/%s ' , $ type ))
37
+ ->will ($ this ->returnValue ($ expectedArray ));
38
+
39
+ $ this ->assertEquals ($ expectedArray , call_user_func (array ($ api , $ type )));
40
+ }
41
+
42
+ /**
43
+ * @return array
44
+ */
45
+ public function getTypes ()
46
+ {
47
+ return array (
48
+ array ('issues ' ),
49
+ array ('hooks ' ),
50
+ array ('milestones ' ),
51
+ array ('orgs ' ),
52
+ array ('comments ' ),
53
+ array ('pages ' ),
54
+ array ('users ' ),
55
+ array ('gists ' ),
56
+ array ('pulls ' ),
57
+ array ('repos ' ),
58
+ array ('all ' )
59
+ );
60
+ }
61
+
62
+ /**
63
+ * @param string $key
64
+ * @return mixed
65
+ */
66
+ protected function getStatsData ($ key = '' )
27
67
{
28
- return '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51,
68
+ $ json = '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51,
29
69
"total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23,
30
70
"inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0,
31
71
"total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45,
@@ -34,6 +74,12 @@ protected function getJson()
34
74
"milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists":
35
75
{ "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6,
36
76
"total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } } ' ;
77
+ $ stats = json_decode ($ json , true );
78
+ if (is_null ($ key )) {
79
+ return $ stats ;
80
+ } elseif (array_key_exists ($ key , $ stats )) {
81
+ return $ stats [$ key ];
82
+ }
37
83
}
38
84
39
85
protected function getApiClass ()
0 commit comments