Skip to content

Commit

Permalink
add unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Aug 17, 2023
1 parent d6fbfca commit 39bb6b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ protected function createCurlSettingsArray(RequestInterface $request): array
$nHeaders[] = $key.': '.$value;
}
}
if(!empty($nHeaders)){

if ([] !== $nHeaders) {
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
}
$settings[CURLOPT_URL] = $request->getUrl();
Expand Down
27 changes: 27 additions & 0 deletions tests/HTTP/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ public function testCreateCurlSettingsArrayGET(): void
self::assertEquals($settings, $client->createCurlSettingsArray($request));
}

public function testCreateCurlSettingsHTTPHeader(): void
{
$client = new ClientMock();
$header = [
'Authorization: Bearer 12345',
];
$client->addCurlSetting(CURLOPT_POSTREDIR, 0);
$client->addCurlSetting(CURLOPT_HTTPHEADER, $header);

$request = new Request('GET', 'http://example.org/');

$settings = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POSTREDIR => 0,
CURLOPT_HTTPHEADER => ['Authorization: Bearer 12345'],
CURLOPT_NOBODY => false,
CURLOPT_URL => 'http://example.org/',
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)',
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
];

self::assertEquals($settings, $client->createCurlSettingsArray($request));
}

public function testCreateCurlSettingsArrayHEAD(): void
{
$client = new ClientMock();
Expand Down

0 comments on commit 39bb6b0

Please sign in to comment.