From 46b4b18eb50b7ef1d45d76b12b2187dc9b33cf1e Mon Sep 17 00:00:00 2001 From: kakaska Date: Thu, 14 Feb 2019 17:52:17 +0100 Subject: [PATCH] Throw BitpayException when BTCPAY server url is empty --- src/Bitpay/Client/Client.php | 5 +++++ tests/Bitpay/Client/ClientTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Bitpay/Client/Client.php b/src/Bitpay/Client/Client.php index dcddbf2..6db989f 100644 --- a/src/Bitpay/Client/Client.php +++ b/src/Bitpay/Client/Client.php @@ -659,9 +659,14 @@ class Client implements ClientInterface /** * @return RequestInterface + * + * @throws BitpayException */ protected function createNewRequest() { + if ($this->uri === null) { + throw new BitpayException('You should provider the url of your BTCPAY server'); + } $request = new Request(); $request->setUri($this->uri); $this->prepareRequestHeaders($request); diff --git a/tests/Bitpay/Client/ClientTest.php b/tests/Bitpay/Client/ClientTest.php index 70376d7..d75b97c 100644 --- a/tests/Bitpay/Client/ClientTest.php +++ b/tests/Bitpay/Client/ClientTest.php @@ -22,6 +22,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->client = new Client(); + $this->client->setUri('https://btcpay.server/'); $this->client->setToken($this->getMockToken()); $this->client->setPublicKey($this->getMockPublicKey()); $this->client->setPrivateKey($this->getMockPrivateKey()); @@ -54,6 +55,16 @@ class ClientTest extends \PHPUnit_Framework_TestCase $res = $client->checkPriceAndCurrency(.991, 'ABC'); } + /** + * @expectedException \Bitpay\Client\BitpayException + * @expectedExceptionMessage You should provider the url of your BTCPAY server + */ + public function testBtcPayServerUrlNotProvided() + { + $client = new Client(); + $client->getTokens(); + } + /** * @expectedException \Exception */