Skip to content

Commit a9be108

Browse files
committed
Api: added withUrl() factory [Ref #18]
1 parent 9adc3b6 commit a9be108

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Github/Api.php

+12
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,18 @@ public function getClient()
318318
}
319319

320320

321+
/**
322+
* @param string
323+
* @return Api
324+
*/
325+
public function withUrl($url)
326+
{
327+
$api = clone $this;
328+
$api->setUrl($url);
329+
return $api;
330+
}
331+
332+
321333
/**
322334
* @param string
323335
* @return self

tests/Github/Api.phpt

+7
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ test(function() {
2929
Assert::same($api, $api->setUrl('url://test'));
3030
Assert::same('url://test', $api->getUrl());
3131

32+
$clone = $api->withUrl('url://cloned');
33+
Assert::notSame($api, $clone);
34+
Assert::same('url://test', $api->getUrl());
35+
Assert::same('url://cloned', $clone->getUrl());
36+
Assert::same($api->getClient(), $clone->getClient());
37+
3238
$token = new Milo\Github\OAuth\Token('hash');
3339
Assert::null($api->getToken());
3440
Assert::same($api, $api->setToken($token));
3541
Assert::same($token, $api->getToken());
3642
$api->setToken(NULL);
3743
Assert::null($api->getToken());
44+
3845
});
3946

4047

0 commit comments

Comments
 (0)