From 39bb6b07a8c9227e2796c3bafba1786c09a4b242 Mon Sep 17 00:00:00 2001 From: amrita Date: Thu, 17 Aug 2023 14:01:57 +0545 Subject: [PATCH] add unit test coverage --- lib/Client.php | 4 ++-- tests/HTTP/ClientTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/Client.php b/lib/Client.php index 93c7538..f2b7a85 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -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(); diff --git a/tests/HTTP/ClientTest.php b/tests/HTTP/ClientTest.php index cb8cefa..9cab23f 100644 --- a/tests/HTTP/ClientTest.php +++ b/tests/HTTP/ClientTest.php @@ -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();