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
12 changes: 9 additions & 3 deletions src/MessageBird/Common/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public function __construct($endpoint, $timeout = 10, $connectionTimeout = 2)
}

/**
* @param $string
* @param string $userAgent
*/
public function addUserAgentString($string)
public function addUserAgentString($userAgent)
{
$this->userAgent[] = $string;
$this->userAgent[] = $userAgent;
}

/**
Expand Down Expand Up @@ -116,12 +116,18 @@ public function getRequestUrl($resourceName, $query)
* @param string|null $body
*
* @return array
*
* @throws Exceptions\AuthenticateException
* @throws Exceptions\HttpException
*/
public function performHttpRequest($method, $resourceName, $query = null, $body = null)
{
$curl = curl_init();

if ($this->Authentication === null) {
throw new Exceptions\AuthenticateException('Can not perform API Request without Authentication');
}

$headers = array (
'User-agent: ' . implode(' ', $this->userAgent),
'Accepts: application/json',
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ public function testHttpClientInvalidConnectionTimeout()
{
new HttpClient(Client::ENDPOINT, 10, new \stdClass());
}

/**
* Test that requests can only be made when there is an Authentication set
*
* @test
* @expectedException \MessageBird\Exceptions\AuthenticateException
* @expectedExceptionMessageRegExp #Can not perform API Request without Authentication#
*/
public function testHttpClientWithoutAuthenticationException()
{
$client = new HttpClient(Client::ENDPOINT);
$client->performHttpRequest('foo', 'bar');
}
}