diff --git a/LiqPay.php b/LiqPay.php index c07c2f2..2cd08fb 100644 --- a/LiqPay.php +++ b/LiqPay.php @@ -114,6 +114,7 @@ public function api($path, $params = array(), $timeout = 15) if ($server_output == NULL) { return array('error' => 'Invalid URL or connection timeout'); } + $this->_server_response_code = $this->curlRequester->get_response_code(); return json_decode($server_output); } @@ -292,6 +293,8 @@ public function str_to_sign($str) class CurlRequester { + private $_server_response_code; + /** * make_curl_request * @param $url string @@ -317,5 +320,9 @@ public function make_curl_request($url, $postfields, $timeout = 15) { } return $server_output; } + + public function get_response_code() { + return $this->_server_response_code; + } } diff --git a/tests/LiqPayTest.php b/tests/LiqPayTest.php index f36fb58..bd775bc 100644 --- a/tests/LiqPayTest.php +++ b/tests/LiqPayTest.php @@ -104,13 +104,18 @@ public function testGetResponseCode() $privateKey = 'your_private_key'; $apiUrl = 'https://api.example.com'; $liqPay = new LiqPay($publicKey, $privateKey, $apiUrl); - - // Set a value to _server_response_code for testing - $reflection = new ReflectionClass($liqPay); - $property = $reflection->getProperty('_server_response_code'); - $property->setAccessible(true); - $property->setValue($liqPay, 200); // Example response code - + + // Mock CURL results + $mockCurlRequester = $this->createMock(CurlRequester::class); + $mockCurlRequester->expects($this->once()) + ->method('make_curl_request') + ->willReturn('{"success":true}'); + $mockCurlRequester->expects($this->once()) + ->method('get_response_code') + ->willReturn(200); + $liqPay->curlRequester = $mockCurlRequester; + + $liqPay->api('/testpath', ['version' => 3, 'action' => 'test']); $responseCode = $liqPay->get_response_code(); $this->assertEquals(200, $responseCode);