diff --git a/CHANGELOG.md b/CHANGELOG.md index d11638f..af9d4b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/spec/XApiClientBuilderSpec.php b/spec/XApiClientBuilderSpec.php index 1605275..0681ecb 100644 --- a/spec/XApiClientBuilderSpec.php +++ b/spec/XApiClientBuilderSpec.php @@ -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'); + } } diff --git a/src/XApiClientBuilder.php b/src/XApiClientBuilder.php index ebd4a1e..193d45e 100644 --- a/src/XApiClientBuilder.php +++ b/src/XApiClientBuilder.php @@ -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)) { diff --git a/src/XApiClientBuilderInterface.php b/src/XApiClientBuilderInterface.php index a2b926f..0e5f08b 100644 --- a/src/XApiClientBuilderInterface.php +++ b/src/XApiClientBuilderInterface.php @@ -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(); }