From 353ec896bd2bb4c34ad4b47dd857084559f12396 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 12 Apr 2017 07:59:41 +0700 Subject: [PATCH] cast to (int) for Curl adapter timeout config --- src/Client/Adapter/Curl.php | 4 ++-- test/Client/CurlTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Client/Adapter/Curl.php b/src/Client/Adapter/Curl.php index 37620e9cfd..4f516aa8cc 100644 --- a/src/Client/Adapter/Curl.php +++ b/src/Client/Adapter/Curl.php @@ -203,9 +203,9 @@ public function connect($host, $port = 80, $secure = false) } if (isset($this->config['connecttimeout'])) { - $connectTimeout = $this->config['connecttimeout']; + $connectTimeout = (int) $this->config['connecttimeout']; } elseif (isset($this->config['timeout'])) { - $connectTimeout = $this->config['timeout']; + $connectTimeout = (int) $this->config['timeout']; } else { $connectTimeout = null; } diff --git a/test/Client/CurlTest.php b/test/Client/CurlTest.php index 89ac19e5f5..bdf5d53495 100644 --- a/test/Client/CurlTest.php +++ b/test/Client/CurlTest.php @@ -95,6 +95,22 @@ public function testConfigSetAsZendConfig() $this->assertEquals($config->nested->item, $hasConfig['nested']['item']); } + /** + * Test not integer timeout casted to int + * + */ + public function testCastTimeOutConfig() + { + $config = new Config([ + 'timeout' => "timeout", + ]); + + $this->_adapter->setOptions($config); + + $hasConfig = $this->_adapter->getConfig(); + $this->assertEquals((int) $config->timeout, $hasConfig['timeout']); + } + /** * Check that an exception is thrown when trying to set invalid config *