diff --git a/src/Interfaces/CurlInterface.php b/src/Interfaces/CurlInterface.php index 7fc82dd..ded8079 100644 --- a/src/Interfaces/CurlInterface.php +++ b/src/Interfaces/CurlInterface.php @@ -20,7 +20,9 @@ */ interface CurlInterface { - public function handle(): CurlHandle; + public function __destruct(); + + public function handle(): ?CurlHandle; public function error(): string; diff --git a/src/Traits/CurlTrait.php b/src/Traits/CurlTrait.php index 5dc1e95..e391bf2 100644 --- a/src/Traits/CurlTrait.php +++ b/src/Traits/CurlTrait.php @@ -51,9 +51,9 @@ public function __destruct() } } - public function handle(): CurlHandle + public function handle(): ?CurlHandle { - return $this->handle; + return isset($this->handle) ? $this->handle : null; } public function error(): string @@ -73,7 +73,7 @@ public function setOptArray(array $options): bool public function close(): void { - curl_close($this->handle); + unset($this->handle); } private function assertCurl(): void diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 877a6d1..8eeb0fb 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -59,6 +59,12 @@ public function testPost(): void CURLOPT_USERAGENT => 'chevere/xr 1.0', ]; $this->assertSame($options, $client->options()); + $curl = $this->createMock(Curl::class); + $curl->expects($this->once()) + ->method('setOptArray') + ->with($options); + $client = $client->withCurl($curl); + $client->sendMessage($message); } public function testCustom(): void