Bladeren bron

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.
Daniele Alessandri 11 jaren geleden
bovenliggende
commit
fdf63bc03d

+ 6 - 1
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'));
         }
     }
 

+ 1 - 1
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);
         }

+ 4 - 1
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()
     {