Skip to content

Commit 31ca116

Browse files
author
guillermo-fisher
committed
Added remaining Stats tests.
1 parent cc01bce commit 31ca116

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

test/Github/Tests/Api/Enterprise/StatsTest.php

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class StatsTest extends TestCase
1111
*/
1212
public function shouldShowStats()
1313
{
14-
$expectedJson = $this->getJson();
15-
$expectedArray = json_decode($expectedJson, true);
14+
$expectedArray = $this->getStatsData();
1615

1716
$api = $this->getApiMock();
1817
$api->expects($this->once())
@@ -23,9 +22,50 @@ public function shouldShowStats()
2322
$this->assertEquals($expectedArray, $api->show('all'));
2423
}
2524

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 = '')
2767
{
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,
2969
"total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23,
3070
"inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0,
3171
"total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45,
@@ -34,6 +74,12 @@ protected function getJson()
3474
"milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists":
3575
{ "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6,
3676
"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+
}
3783
}
3884

3985
protected function getApiClass()

0 commit comments

Comments
 (0)