From 00a3b8cbb254a4d6c038847807b0a2213ef66db5 Mon Sep 17 00:00:00 2001 From: Adonis Figueroa Date: Wed, 21 Sep 2016 13:24:44 +0200 Subject: [PATCH 1/4] Options to timeout --- lib/Tinify.php | 11 +++++++++++ lib/Tinify/Client.php | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Tinify.php b/lib/Tinify.php index f37c244..041e2d2 100644 --- a/lib/Tinify.php +++ b/lib/Tinify.php @@ -9,6 +9,7 @@ class Tinify { private static $appIdentifier = NULL; private static $compressionCount = NULL; private static $client = NULL; + private static $options = array(); public static function setKey($key) { self::$key = $key; @@ -37,12 +38,18 @@ public static function getClient() { self::$client = new Client(self::$key, self::$appIdentifier); } + self::$client->setExtraOptions(self::$options); + return self::$client; } public static function setClient($client) { self::$client = $client; } + + public static function setExtraOptions($options=array()) { + self::$options = $options; + } } function setKey($key) { @@ -83,3 +90,7 @@ function validate() { return true; } } + +function setExtraOptions($options=array()) { + return Tinify::setExtraOptions($options); +} \ No newline at end of file diff --git a/lib/Tinify/Client.php b/lib/Tinify/Client.php index f76f09a..3f8a59a 100644 --- a/lib/Tinify/Client.php +++ b/lib/Tinify/Client.php @@ -105,4 +105,19 @@ protected static function parseHeaders($headers) { } return $res; } + + function setExtraOptions($options) { + if (isset($options['CURLOPT_CONNECTTIMEOUT'])) { + $this->options[CURLOPT_CONNECTTIMEOUT] = $options['CURLOPT_CONNECTTIMEOUT']; + } + if (isset($options['CURLOPT_CONNECTTIMEOUT_MS'])) { + $this->options[CURLOPT_CONNECTTIMEOUT_MS] = $options['CURLOPT_CONNECTTIMEOUT_MS']; + } + if (isset($options['CURLOPT_TIMEOUT'])) { + $this->options[CURLOPT_TIMEOUT] = $options['CURLOPT_TIMEOUT']; + } + if (isset($options['CURLOPT_TIMEOUT_MS'])) { + $this->options[CURLOPT_TIMEOUT_MS] = $options['CURLOPT_TIMEOUT_MS']; + } + } } From fd79d5d36aa6f8a5d6c9ef3def653a44db0ba871 Mon Sep 17 00:00:00 2001 From: Adonis Figueroa Date: Thu, 22 Sep 2016 21:29:45 +0200 Subject: [PATCH 2/4] Test for set Extra Options --- composer.lock | 257 ++++++++++++++++++++++++++++++-------- lib/Tinify.php | 3 +- test/TinifyClientTest.php | 11 ++ 3 files changed, 216 insertions(+), 55 deletions(-) diff --git a/composer.lock b/composer.lock index aa679b7..0c79311 100644 --- a/composer.lock +++ b/composer.lock @@ -62,39 +62,136 @@ ], "time": "2015-06-14 21:17:01" }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, { "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", + "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-06-10 09:48:41" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { - "psr-0": { - "phpDocumentor": [ + "psr-4": { + "phpDocumentor\\Reflection\\": [ "src/" ] } @@ -106,39 +203,39 @@ "authors": [ { "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" + "email": "me@mikevanriel.com" } ], - "time": "2015-02-03 12:10:50" + "time": "2016-06-10 07:14:17" }, { "name": "phpspec/prophecy", - "version": "v1.6.0", + "version": "v1.6.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972" + "reference": "58a8137754bc24b25740d4281399a4a3596058e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972", - "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0", + "reference": "58a8137754bc24b25740d4281399a4a3596058e0", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1", - "sebastian/recursion-context": "~1.0" + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0" }, "require-dev": { - "phpspec/phpspec": "~2.0" + "phpspec/phpspec": "^2.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -171,7 +268,7 @@ "spy", "stub" ], - "time": "2016-02-15 07:46:21" + "time": "2016-06-07 08:13:47" }, { "name": "phpunit/php-code-coverage", @@ -325,21 +422,24 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.7", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, "type": "library", "autoload": { "classmap": [ @@ -362,7 +462,7 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2016-05-12 18:03:57" }, { "name": "phpunit/php-token-stream", @@ -415,16 +515,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.24", + "version": "4.8.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a1066c562c52900a142a0e2bbf0582994671385e" + "reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1066c562c52900a142a0e2bbf0582994671385e", - "reference": "a1066c562c52900a142a0e2bbf0582994671385e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c062dddcb68e44b563f66ee319ddae2b5a322a90", + "reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90", "shasum": "" }, "require": { @@ -438,7 +538,7 @@ "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": ">=1.0.6", + "phpunit/php-timer": "^1.0.6", "phpunit/phpunit-mock-objects": "~2.3", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", @@ -483,7 +583,7 @@ "testing", "xunit" ], - "time": "2016-03-14 06:16:08" + "time": "2016-07-21 06:48:14" }, { "name": "phpunit/phpunit-mock-objects", @@ -659,23 +759,23 @@ }, { "name": "sebastian/environment", - "version": "1.3.5", + "version": "1.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf" + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { @@ -705,20 +805,20 @@ "environment", "hhvm" ], - "time": "2016-02-26 18:40:46" + "time": "2016-08-18 05:49:44" }, { "name": "sebastian/exporter", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e" + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", "shasum": "" }, "require": { @@ -726,12 +826,13 @@ "sebastian/recursion-context": "~1.0" }, "require-dev": { + "ext-mbstring": "*", "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -771,7 +872,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2016-06-17 09:04:28" }, { "name": "sebastian/global-state", @@ -914,16 +1015,16 @@ }, { "name": "symfony/yaml", - "version": "v2.8.4", + "version": "v2.8.11", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb" + "reference": "e7540734bad981fe59f8ef14b6fc194ae9df8d9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb", - "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb", + "url": "https://api.github.com/repos/symfony/yaml/zipball/e7540734bad981fe59f8ef14b6fc194ae9df8d9c", + "reference": "e7540734bad981fe59f8ef14b6fc194ae9df8d9c", "shasum": "" }, "require": { @@ -959,7 +1060,57 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:54:35" + "time": "2016-09-02 01:57:56" + }, + { + "name": "webmozart/assert", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308", + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308", + "shasum": "" + }, + "require": { + "php": "^5.3.3|^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-08-09 15:02:57" } ], "aliases": [], diff --git a/lib/Tinify.php b/lib/Tinify.php index 041e2d2..91fe282 100644 --- a/lib/Tinify.php +++ b/lib/Tinify.php @@ -36,10 +36,9 @@ public static function getClient() { if (!self::$client) { self::$client = new Client(self::$key, self::$appIdentifier); + self::$client->setExtraOptions(self::$options); } - self::$client->setExtraOptions(self::$options); - return self::$client; } diff --git a/test/TinifyClientTest.php b/test/TinifyClientTest.php index b05f936..7ebb963 100644 --- a/test/TinifyClientTest.php +++ b/test/TinifyClientTest.php @@ -173,4 +173,15 @@ public function testRequestWithBadCredentialsShouldThrowExceptionWithMessage() { $client = new Tinify\Client("key"); $client->request("get", "/"); } + + public function testRequestWithServerTimeoutErrorShouldThrowExceptionWithMessage() { + CurlMock::register("https://api.tinify.com/", array( + "error" => "Operation timed out after 1001 milliseconds with 0 bytes received", "errno" => 28 + )); + $this->setExpectedExceptionRegExp("Tinify\ConnectionException", + "/Error while connecting: Operation timed out after 1001 milliseconds with 0 bytes received \(#28\)/"); + $client = new Tinify\Client("key"); + $client->setExtraOptions(array('CURLOPT_CONNECTTIMEOUT'=>1, 'CURLOPT_TIMEOUT'=>1)); + $client->request("get", "/"); + } } From cd3fae28abf2ed9c8d00d24260eddb78f56ec446 Mon Sep 17 00:00:00 2001 From: Adonis Figueroa Date: Sat, 24 Sep 2016 18:22:53 +0200 Subject: [PATCH 3/4] New functions for Requst Timeout and Connection Timeout --- lib/Tinify.php | 58 +++++++++++++++++++++++++++++++++------ lib/Tinify/Client.php | 27 +++++++++--------- test/TinifyClientTest.php | 35 ++++++++++++++++++++++- 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/lib/Tinify.php b/lib/Tinify.php index 91fe282..616daee 100644 --- a/lib/Tinify.php +++ b/lib/Tinify.php @@ -9,7 +9,10 @@ class Tinify { private static $appIdentifier = NULL; private static $compressionCount = NULL; private static $client = NULL; - private static $options = array(); + private static $requestTimeout = -1; + private static $requestTimeoutMS = -1; + private static $connectionTimeout = -1; + private static $connectionTimeoutMS = -1; public static function setKey($key) { self::$key = $key; @@ -36,7 +39,18 @@ public static function getClient() { if (!self::$client) { self::$client = new Client(self::$key, self::$appIdentifier); - self::$client->setExtraOptions(self::$options); + if (self::$requestTimeout > -1) { + self::$client->setRequestTimeout(self::$requestTimeout); + } + if (self::$requestTimeoutMS > -1) { + self::$client->setRequestTimeoutMS(self::$requestTimeoutMS); + } + if (self::$connectionTimeout > -1) { + self::$client->setConnectionTimeout(self::$connectionTimeout); + } + if (self::$connectionTimeoutMS > -1) { + self::$client->setConnectionTimeoutMS(self::$connectionTimeoutMS); + } } return self::$client; @@ -46,8 +60,24 @@ public static function setClient($client) { self::$client = $client; } - public static function setExtraOptions($options=array()) { - self::$options = $options; + public function setRequestTimeout($seconds) + { + self::$requestTimeout = $seconds; + } + + public function setRequestTimeoutMS($milliseconds) + { + self::$requestTimeoutMS = $milliseconds; + } + + public function setConnectionTimeout($seconds) + { + self::$connectionTimeout = $seconds; + } + + public function setConnectionTimeoutMS($milliseconds) + { + self::$connectionTimeoutMS = $milliseconds; } } @@ -67,6 +97,22 @@ function compressionCount() { return Tinify::getCompressionCount(); } +function setRequestTimeout($seconds) { + return Tinify::setRequestTimeout($seconds); +} + +function setRequestTimeoutMS($milliseconds) { + return Tinify::setRequestTimeoutMS($milliseconds); +} + +function setConnectionTimeout($seconds) { + return Tinify::setConnectionTimeout($seconds); +} + +function setConnectionTimeoutMS($milliseconds) { + return Tinify::setConnectionTimeoutMS($milliseconds); +} + function fromFile($path) { return Source::fromFile($path); } @@ -89,7 +135,3 @@ function validate() { return true; } } - -function setExtraOptions($options=array()) { - return Tinify::setExtraOptions($options); -} \ No newline at end of file diff --git a/lib/Tinify/Client.php b/lib/Tinify/Client.php index 3f8a59a..efefda8 100644 --- a/lib/Tinify/Client.php +++ b/lib/Tinify/Client.php @@ -106,18 +106,19 @@ protected static function parseHeaders($headers) { return $res; } - function setExtraOptions($options) { - if (isset($options['CURLOPT_CONNECTTIMEOUT'])) { - $this->options[CURLOPT_CONNECTTIMEOUT] = $options['CURLOPT_CONNECTTIMEOUT']; - } - if (isset($options['CURLOPT_CONNECTTIMEOUT_MS'])) { - $this->options[CURLOPT_CONNECTTIMEOUT_MS] = $options['CURLOPT_CONNECTTIMEOUT_MS']; - } - if (isset($options['CURLOPT_TIMEOUT'])) { - $this->options[CURLOPT_TIMEOUT] = $options['CURLOPT_TIMEOUT']; - } - if (isset($options['CURLOPT_TIMEOUT_MS'])) { - $this->options[CURLOPT_TIMEOUT_MS] = $options['CURLOPT_TIMEOUT_MS']; - } + function setRequestTimeout($seconds) { + $this->options[CURLOPT_TIMEOUT] = $seconds; + } + + function setRequestTimeoutMS($milliseconds) { + $this->options[CURLOPT_TIMEOUT_MS] = $milliseconds; + } + + function setConnectionTimeout($seconds) { + $this->options[CURLOPT_CONNECTTIMEOUT] = $seconds; + } + + function setConnectionTimeoutMS($milliseconds) { + $this->options[CURLOPT_CONNECTTIMEOUT_MS] = $milliseconds; } } diff --git a/test/TinifyClientTest.php b/test/TinifyClientTest.php index 7ebb963..3a45638 100644 --- a/test/TinifyClientTest.php +++ b/test/TinifyClientTest.php @@ -181,7 +181,40 @@ public function testRequestWithServerTimeoutErrorShouldThrowExceptionWithMessage $this->setExpectedExceptionRegExp("Tinify\ConnectionException", "/Error while connecting: Operation timed out after 1001 milliseconds with 0 bytes received \(#28\)/"); $client = new Tinify\Client("key"); - $client->setExtraOptions(array('CURLOPT_CONNECTTIMEOUT'=>1, 'CURLOPT_TIMEOUT'=>1)); + $client->setRequestTimeout(1); + $client->request("get", "/"); + } + + public function testRequestWithServerTimeoutMSErrorShouldThrowExceptionWithMessage() { + CurlMock::register("https://api.tinify.com/", array( + "error" => "Operation timed out after 2 milliseconds with 0 bytes received", "errno" => 28 + )); + $this->setExpectedExceptionRegExp("Tinify\ConnectionException", + "/Error while connecting: Operation timed out after 2 milliseconds with 0 bytes received \(#28\)/"); + $client = new Tinify\Client("key"); + $client->setRequestTimeoutMS(1); + $client->request("get", "/"); + } + + public function testRequestWithServerConnectionTimeoutErrorShouldThrowExceptionWithMessage() { + CurlMock::register("https://api.tinify.com/", array( + "error" => "Connection timed out after 1001 milliseconds", "errno" => 28 + )); + $this->setExpectedExceptionRegExp("Tinify\ConnectionException", + "/Error while connecting: Connection timed out after 1001 milliseconds \(#28\)/"); + $client = new Tinify\Client("key"); + $client->setConnectionTimeout(1); + $client->request("get", "/"); + } + + public function testRequestWithServerConnectionTimeoutMSErrorShouldThrowExceptionWithMessage() { + CurlMock::register("https://api.tinify.com/", array( + "error" => "Connection timed out after 2 milliseconds", "errno" => 28 + )); + $this->setExpectedExceptionRegExp("Tinify\ConnectionException", + "/Error while connecting: Connection timed out after 2 milliseconds \(#28\)/"); + $client = new Tinify\Client("key"); + $client->setConnectionTimeoutMS(1); $client->request("get", "/"); } } From f348b40714fec00827e1beb8758a6173302b8da6 Mon Sep 17 00:00:00 2001 From: Adonis Figueroa Date: Sat, 12 Nov 2016 20:32:02 +0100 Subject: [PATCH 4/4] Declare functions as Static --- composer.lock | 20 ++++++++++---------- lib/Tinify.php | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.lock b/composer.lock index 0c79311..3dc3308 100644 --- a/composer.lock +++ b/composer.lock @@ -118,16 +118,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", "shasum": "" }, "require": { @@ -159,7 +159,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-06-10 09:48:41" + "time": "2016-09-30 07:12:33" }, { "name": "phpdocumentor/type-resolver", @@ -1015,16 +1015,16 @@ }, { "name": "symfony/yaml", - "version": "v2.8.11", + "version": "v2.8.13", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "e7540734bad981fe59f8ef14b6fc194ae9df8d9c" + "reference": "396784cd06b91f3db576f248f2402d547a077787" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/e7540734bad981fe59f8ef14b6fc194ae9df8d9c", - "reference": "e7540734bad981fe59f8ef14b6fc194ae9df8d9c", + "url": "https://api.github.com/repos/symfony/yaml/zipball/396784cd06b91f3db576f248f2402d547a077787", + "reference": "396784cd06b91f3db576f248f2402d547a077787", "shasum": "" }, "require": { @@ -1060,7 +1060,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-09-02 01:57:56" + "time": "2016-10-21 20:59:10" }, { "name": "webmozart/assert", diff --git a/lib/Tinify.php b/lib/Tinify.php index 616daee..0075afe 100644 --- a/lib/Tinify.php +++ b/lib/Tinify.php @@ -60,22 +60,22 @@ public static function setClient($client) { self::$client = $client; } - public function setRequestTimeout($seconds) + public static function setRequestTimeout($seconds) { self::$requestTimeout = $seconds; } - public function setRequestTimeoutMS($milliseconds) + public static function setRequestTimeoutMS($milliseconds) { self::$requestTimeoutMS = $milliseconds; } - public function setConnectionTimeout($seconds) + public static function setConnectionTimeout($seconds) { self::$connectionTimeout = $seconds; } - public function setConnectionTimeoutMS($milliseconds) + public static function setConnectionTimeoutMS($milliseconds) { self::$connectionTimeoutMS = $milliseconds; }