summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRolf Timmermans <rolftimmermans@voormedia.com>2017-07-19 14:32:26 +0200
committerRolf Timmermans <rolftimmermans@voormedia.com>2017-07-19 14:32:26 +0200
commit7c76bcc8eaa6f78b6c0ab29b429a63508d60a40e (patch)
tree388e2ac47af87429ef54abb547b3f0be892420ee
parent45e79fee561f6264dfa10f423a121a1a5293089a (diff)
parentb15d1f31d94d9b06e60251543cc918f426f0d55b (diff)
downloadtinify-php-7c76bcc8eaa6f78b6c0ab29b429a63508d60a40e.zip
tinify-php-7c76bcc8eaa6f78b6c0ab29b429a63508d60a40e.tar.gz
tinify-php-7c76bcc8eaa6f78b6c0ab29b429a63508d60a40e.tar.bz2
Merge checks for curl/openssl.
-rw-r--r--.travis.yml4
-rw-r--r--CHANGES.md6
-rw-r--r--lib/Tinify.php2
-rw-r--r--lib/Tinify/Client.php11
-rw-r--r--test/TinifyClientTest.php19
-rw-r--r--test/curl_mock.php20
-rw-r--r--test/helper.php1
-rw-r--r--test/integration.php1
8 files changed, 62 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index 4dfd033..bcb7dc5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,6 @@ php:
- 5.6
- 7.0
- 7.1
-- hhvm
- nightly
env:
global:
@@ -15,6 +14,9 @@ matrix:
allow_failures:
- php: nightly
include:
+ - php: hhvm
+ dist: trusty
+ include:
- php: 5.6
env: INTEGRATION_TESTS=true
script: "if [ \"$TRAVIS_PULL_REQUEST\" == \"false\" ]; then vendor/bin/phpunit --no-configuration test/integration.php; fi"
diff --git a/CHANGES.md b/CHANGES.md
index cdd33c5..c0c95e0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,9 @@
+## 1.5.2
+* Fail early if version of curl/openssl is too old.
+
+## 1.5.1
+* Expose status of exceptions.
+
## 1.5.0
* Retry failed requests by default.
* Throw clearer errors when curl is installed but disabled.
diff --git a/lib/Tinify.php b/lib/Tinify.php
index 807d127..8157f4b 100644
--- a/lib/Tinify.php
+++ b/lib/Tinify.php
@@ -2,7 +2,7 @@
namespace Tinify;
-const VERSION = "1.5.0";
+const VERSION = "1.5.2";
class Tinify {
const AUTHENTICATED = true;
diff --git a/lib/Tinify/Client.php b/lib/Tinify/Client.php
index 154a04a..b669700 100644
--- a/lib/Tinify/Client.php
+++ b/lib/Tinify/Client.php
@@ -22,6 +22,17 @@ class Client {
function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
$userAgent = join(" ", array_filter(array(self::userAgent(), $appIdentifier)));
+ $curl = curl_version();
+
+ if (!($curl["features"] & CURL_VERSION_SSL)) {
+ throw new ClientException("Your curl version does not support secure connections");
+ }
+
+ if ($curl["version_number"] < 0x071201) {
+ $version = $curl["version"];
+ throw new ClientException("Your curl version ${version} is outdated; please upgrade to 7.18.1 or higher");
+ }
+
$this->options = array(
CURLOPT_BINARYTRANSFER => true,
CURLOPT_RETURNTRANSFER => true,
diff --git a/test/TinifyClientTest.php b/test/TinifyClientTest.php
index d298763..9f25c7d 100644
--- a/test/TinifyClientTest.php
+++ b/test/TinifyClientTest.php
@@ -301,4 +301,23 @@ class TinifyClientTest extends TestCase {
$client = new Tinify\Client("key");
$client->request("get", "/");
}
+
+ public function testRequestWithNoSSLCurlShouldThrowExceptionWithMessage() {
+ CurlMock::register("https://api.tinify.com/", array("status" => 200));
+ CurlMock::set_version_info_key("features", (CURL_VERSION_LIBZ | CURL_VERSION_IPV6));
+ $this->setExpectedException("Tinify\ClientException",
+ "Your curl version does not support secure connections");
+ $client = new Tinify\Client("key");
+ $client->request("get", "/");
+ }
+
+ public function testRequestWithOutdatedCurlShouldThrowExceptionWithMessage() {
+ CurlMock::register("https://api.tinify.com/", array("status" => 200));
+ CurlMock::set_version_info_key("version_number", 0x070f05);
+ CurlMock::set_version_info_key("version", "7.15.5");
+ $this->setExpectedException("Tinify\ClientException",
+ "Your curl version 7.15.5 is outdated; please upgrade to 7.18.1 or higher");
+ $client = new Tinify\Client("key");
+ $client->request("get", "/");
+ }
}
diff --git a/test/curl_mock.php b/test/curl_mock.php
index d02525e..6d344bc 100644
--- a/test/curl_mock.php
+++ b/test/curl_mock.php
@@ -6,13 +6,28 @@ class CurlMockException extends Exception {
}
class CurlMock {
+ private static $default_version = array(
+ "version_number" => 471808,
+ "version" => "7.51.0",
+ "features" => 951197,
+ );
+
private static $urls = array();
private static $requests = array();
+ private static $version = array();
public $options = array();
public $response;
public $closed = false;
+ public static function version_info() {
+ return self::$version;
+ }
+
+ public static function set_version_info_key($key, $value) {
+ self::$version[$key] = $value;
+ }
+
public static function register($url, $request, $response = NULL) {
if (!$response) {
$response = $request;
@@ -29,6 +44,7 @@ class CurlMock {
public static function reset() {
self::$requests = array();
self::$urls = array();
+ self::$version = self::$default_version;
}
public static function last_has($key) {
@@ -138,6 +154,10 @@ class CurlMock {
}
}
+function curl_version() {
+ return CurlMock::version_info();
+}
+
function curl_init() {
return new CurlMock();
}
diff --git a/test/helper.php b/test/helper.php
index 489d5c3..a2536ce 100644
--- a/test/helper.php
+++ b/test/helper.php
@@ -5,6 +5,7 @@ require_once("vendor/autoload.php");
class TestCase extends \PHPUnit_Framework_TestCase {
function setUp() {
+ Tinify\CurlMock::reset();
Tinify\setKey(NULL);
TInify\setProxy(NULL);
}
diff --git a/test/integration.php b/test/integration.php
index 746a124..2682bd3 100644
--- a/test/integration.php
+++ b/test/integration.php
@@ -10,6 +10,7 @@ class ClientIntegrationTest extends PHPUnit_Framework_TestCase {
static public function setUpBeforeClass() {
\Tinify\setKey(getenv("TINIFY_KEY"));
\Tinify\setProxy(getenv("TINIFY_PROXY"));
+ \Tinify\validate();
$unoptimizedPath = __DIR__ . "/examples/voormedia.png";
self::$optimized = \Tinify\fromFile($unoptimizedPath);