[Cache] fix checking for igbinary availability

This commit is contained in:
Nicolas Grekas 2020-01-22 08:15:02 +01:00
parent f2cf444fb0
commit 09818e99ac
3 changed files with 9 additions and 9 deletions

View File

@ -172,7 +172,7 @@ before_install:
tfold ext.apcu tpecl apcu-5.1.17 apcu.so $INI tfold ext.apcu tpecl apcu-5.1.17 apcu.so $INI
tfold ext.mongodb tpecl mongodb-1.6.0alpha1 mongodb.so $INI tfold ext.mongodb tpecl mongodb-1.6.0alpha1 mongodb.so $INI
tfold ext.igbinary tpecl igbinary-2.0.8 igbinary.so $INI tfold ext.igbinary tpecl igbinary-3.1.2 igbinary.so $INI
tfold ext.zookeeper tpecl zookeeper-0.7.1 zookeeper.so $INI tfold ext.zookeeper tpecl zookeeper-0.7.1 zookeeper.so $INI
tfold ext.amqp tpecl amqp-1.9.4 amqp.so $INI tfold ext.amqp tpecl amqp-1.9.4 amqp.so $INI
tfold ext.redis tpecl redis-4.3.0 redis.so $INI "no" tfold ext.redis tpecl redis-4.3.0 redis.so $INI "no"

View File

@ -25,9 +25,9 @@ class DefaultMarshaller implements MarshallerInterface
public function __construct(bool $useIgbinarySerialize = null) public function __construct(bool $useIgbinarySerialize = null)
{ {
if (null === $useIgbinarySerialize) { if (null === $useIgbinarySerialize) {
$useIgbinarySerialize = \extension_loaded('igbinary') && \PHP_VERSION_ID < 70400; $useIgbinarySerialize = \extension_loaded('igbinary') && (\PHP_VERSION_ID < 70400 || version_compare('3.1.0', phpversion('igbinary'), '<='));
} elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || \PHP_VERSION_ID >= 70400)) { } elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || (\PHP_VERSION_ID >= 70400 && version_compare('3.1.0', phpversion('igbinary'), '>')))) {
throw new CacheException('The "igbinary" PHP extension is not '.(\PHP_VERSION_ID >= 70400 ? 'compatible with PHP 7.4.' : 'loaded.')); throw new CacheException(\extension_loaded('igbinary') && \PHP_VERSION_ID >= 70400 ? 'Please upgrade the "igbinary" PHP extension to v3.1 or higher.' : 'The "igbinary" PHP extension is not loaded.');
} }
$this->useIgbinarySerialize = $useIgbinarySerialize; $this->useIgbinarySerialize = $useIgbinarySerialize;
} }
@ -66,7 +66,7 @@ class DefaultMarshaller implements MarshallerInterface
return null; return null;
} }
static $igbinaryNull; static $igbinaryNull;
if ($value === ($igbinaryNull ?? $igbinaryNull = \extension_loaded('igbinary') && \PHP_VERSION_ID < 70400 ? igbinary_serialize(null) : false)) { if ($value === ($igbinaryNull ?? $igbinaryNull = \extension_loaded('igbinary') && (\PHP_VERSION_ID < 70400 || version_compare('3.1.0', phpversion('igbinary'), '<=')) ? igbinary_serialize(null) : false)) {
return null; return null;
} }
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback'); $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');

View File

@ -24,7 +24,7 @@ class DefaultMarshallerTest extends TestCase
'b' => function () {}, 'b' => function () {},
]; ];
$expected = ['a' => \extension_loaded('igbinary') && \PHP_VERSION_ID < 70400 ? igbinary_serialize(123) : serialize(123)]; $expected = ['a' => \extension_loaded('igbinary') && (\PHP_VERSION_ID < 70400 || version_compare('3.1.0', phpversion('igbinary'), '<=')) ? igbinary_serialize(123) : serialize(123)];
$this->assertSame($expected, $marshaller->marshall($values, $failed)); $this->assertSame($expected, $marshaller->marshall($values, $failed));
$this->assertSame(['b'], $failed); $this->assertSame(['b'], $failed);
} }
@ -43,7 +43,7 @@ class DefaultMarshallerTest extends TestCase
*/ */
public function testIgbinaryUnserialize() public function testIgbinaryUnserialize()
{ {
if (\PHP_VERSION_ID >= 70400) { if (\PHP_VERSION_ID >= 70400 && version_compare('3.1.0', phpversion('igbinary'), '>')) {
$this->markTestSkipped('igbinary is not compatible with PHP 7.4.'); $this->markTestSkipped('igbinary is not compatible with PHP 7.4.');
} }
@ -67,7 +67,7 @@ class DefaultMarshallerTest extends TestCase
*/ */
public function testIgbinaryUnserializeNotFoundClass() public function testIgbinaryUnserializeNotFoundClass()
{ {
if (\PHP_VERSION_ID >= 70400) { if (\PHP_VERSION_ID >= 70400 && version_compare('3.1.0', phpversion('igbinary'), '>')) {
$this->markTestSkipped('igbinary is not compatible with PHP 7.4.'); $this->markTestSkipped('igbinary is not compatible with PHP 7.4.');
} }
@ -95,7 +95,7 @@ class DefaultMarshallerTest extends TestCase
*/ */
public function testIgbinaryUnserializeInvalid() public function testIgbinaryUnserializeInvalid()
{ {
if (\PHP_VERSION_ID >= 70400) { if (\PHP_VERSION_ID >= 70400 && version_compare('3.1.0', phpversion('igbinary'), '>')) {
$this->markTestSkipped('igbinary is not compatible with PHP 7.4.'); $this->markTestSkipped('igbinary is not compatible with PHP 7.4.');
} }