Skip to content

Commit 3e0839f

Browse files
committed
Tests and catching of InvalidArgumentException within __call
1 parent af024a6 commit 3e0839f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Github/Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ public function getSupportedApiVersions()
315315
* @throws InvalidArgumentException
316316
*/
317317
public function __call($name, $args) {
318-
return $this->api($name);
318+
try {
319+
return $this->api($name);
320+
} catch (InvalidArgumentException $e) {
321+
throw new BadMethodCallException(sprintf('Undefined method called: "%s"', $name));
322+
}
319323
}
320324
}

test/Github/Tests/ClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ public function shouldGetApiInstance($apiName, $class)
124124
$this->assertInstanceOf($class, $client->api($apiName));
125125
}
126126

127+
/**
128+
* @test
129+
* @dataProvider getApiClassesProvider
130+
*/
131+
public function shouldGetMagicApiInstance($apiName, $class)
132+
{
133+
$client = new Client();
134+
135+
$this->assertInstanceOf($class, $client->$apiName());
136+
}
137+
127138
/**
128139
* @test
129140
* @expectedException InvalidArgumentException
@@ -142,9 +153,11 @@ public function getApiClassesProvider()
142153

143154
array('me', 'Github\Api\CurrentUser'),
144155
array('current_user', 'Github\Api\CurrentUser'),
156+
array('currentUser', 'Github\Api\CurrentUser'),
145157

146158
array('git', 'Github\Api\GitData'),
147159
array('git_data', 'Github\Api\GitData'),
160+
array('gitData', 'Github\Api\GitData'),
148161

149162
array('gist', 'Github\Api\Gists'),
150163
array('gists', 'Github\Api\Gists'),
@@ -163,7 +176,9 @@ public function getApiClassesProvider()
163176
array('repositories', 'Github\Api\Repo'),
164177

165178
array('pr', 'Github\Api\PullRequest'),
179+
array('pullRequest', 'Github\Api\PullRequest'),
166180
array('pull_request', 'Github\Api\PullRequest'),
181+
array('pullRequests', 'Github\Api\PullRequest'),
167182
array('pull_requests', 'Github\Api\PullRequest'),
168183

169184
array('authorization', 'Github\Api\Authorizations'),

0 commit comments

Comments
 (0)