From fdf63bc03d6f02ab0f22a8c2ec31462402dc93cd Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Tue, 17 Dec 2013 16:09:20 +0100 Subject: [PATCH] Make Predis compatible with HHVM (at least 2.3.0). Achieving compatibility actually required a few marginal changes: - HHVM still has some issues with re-entrant calls to __get(). The applied change is an hack simply because it is ugly, but it is not wrong and does not break the signature of the options interface. - Since we cannot rely on the PHP version to detect the availability of socket_import_stream(), we switched to function_exists(). As an added bonus, using function_exists() is twice faster. - In the test suite we removed an assertion for the message of an E_WARNING simply because HHVM emits a different message. Checking for the warning is actually enough in that context. While the whole test suite passes on HHVM 2.3.0, please remember that HHVM is still in development and things could break anytime especially in some obscure corner cases. --- lib/Predis/Configuration/ProfileOption.php | 7 ++++++- lib/Predis/Connection/StreamConnection.php | 2 +- tests/Predis/Command/RawCommandTest.php | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Predis/Configuration/ProfileOption.php b/lib/Predis/Configuration/ProfileOption.php index 45385e6b..300f7d47 100644 --- a/lib/Predis/Configuration/ProfileOption.php +++ b/lib/Predis/Configuration/ProfileOption.php @@ -33,7 +33,12 @@ class ProfileOption implements OptionInterface protected function setProcessors(OptionsInterface $options, ProfileInterface $profile) { if (isset($options->prefix) && $profile instanceof RedisProfile) { - $profile->setProcessor($options->prefix); + // NOTE: directly using __get('prefix') is actually a workaround for + // HHVM 2.3.0. It's correct and respects the options interface, it's + // just ugly. We will remove this hack when HHVM will fix re-entrant + // calls to __get() once and for all. + + $profile->setProcessor($options->__get('prefix')); } } diff --git a/lib/Predis/Connection/StreamConnection.php b/lib/Predis/Connection/StreamConnection.php index 02b23268..5ff686a1 100644 --- a/lib/Predis/Connection/StreamConnection.php +++ b/lib/Predis/Connection/StreamConnection.php @@ -92,7 +92,7 @@ class StreamConnection extends AbstractConnection stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds); } - if (isset($parameters->tcp_nodelay) && version_compare(PHP_VERSION, '5.4.0') >= 0) { + if (isset($parameters->tcp_nodelay) && function_exists('socket_import_stream')) { $socket = socket_import_stream($resource); socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int) $parameters->tcp_nodelay); } diff --git a/tests/Predis/Command/RawCommandTest.php b/tests/Predis/Command/RawCommandTest.php index 7ebf5eb0..b9b07fe5 100644 --- a/tests/Predis/Command/RawCommandTest.php +++ b/tests/Predis/Command/RawCommandTest.php @@ -69,9 +69,12 @@ class RawCommandTest extends PredisTestCase } /** + * The signature of RawCommand::create() requires one argument which is the + * ID of the command (other arguments are fetched dinamically). If the first + * argument is missing, PHP emits an E_WARNING. + * * @group disconnected * @expectedException PHPUnit_Framework_Error_Warning - * @expectedExceptionMessage Missing argument 1 for Predis\Command\RawCommand::create() */ public function testPHPWarningOnMissingCommandIDWithStaticCreate() {