Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ CHANGELOG
0.3.0
-----

* Fixed creating `XApiClient` instances in an invalid state. The `XApiClientBuilder`
now throws a `\LogicException` when the `build()` method is called before
a base URI was configured.

* Removed the `ApiClient` class. The `$requestHandler` and `$version` attributes
have been moved to the former child classes of the `ApiClient` class and
their visibility has been changed to `private`.
Expand Down
6 changes: 6 additions & 0 deletions spec/XApiClientBuilderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ function it_is_an_xapi_client_builder()

function it_creates_an_xapi_client()
{
$this->setBaseUrl('http://example.com/xapi/');
$this->build()->shouldHaveType('Xabbuh\XApi\Client\XApiClientInterface');
}

function it_throws_an_exception_if_the_base_uri_is_not_configured()
{
$this->shouldThrow('\LogicException')->during('build');
}
}
4 changes: 4 additions & 0 deletions src/XApiClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public function setOAuthCredentials($consumerKey, $consumerSecret, $token, $toke
*/
public function build()
{
if (null === $this->baseUrl) {
throw new \LogicException('Base URI value was not configured.');
}

$httpClient = new Client($this->baseUrl);

if (is_array($this->oAuthCredentials)) {
Expand Down
2 changes: 2 additions & 0 deletions src/XApiClientBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function setOAuthCredentials($consumerKey, $consumerSecret, $token, $toke
* Builds the xAPI client.
*
* @return XApiClientInterface The xAPI client
*
* @throws \LogicException if no base URI was configured
*/
public function build();
}