THRIFT-5757: finish PHP cross-test integration
diff --git a/test/php/Handler.php b/test/php/Handler.php
index 3ea1f58..a03554c 100644
--- a/test/php/Handler.php
+++ b/test/php/Handler.php
@@ -89,31 +89,87 @@
 
     public function testMapMap($hello)
     {
-        return $hello;
+        return [
+            -4 => [
+                -4 => -4,
+                -3 => -3,
+                -2 => -2,
+                -1 => -1,
+            ],
+            4 => [
+                4 => 4,
+                3 => 3,
+                2 => 2,
+                1 => 1,
+            ],
+        ];
     }
 
     public function testInsanity(\ThriftTest\Insanity $argument)
     {
-        return $argument;
+        $looney = new \ThriftTest\Insanity();
+
+        return [
+            1 => [
+                \ThriftTest\Numberz::TWO => $argument,
+                \ThriftTest\Numberz::THREE => $argument,
+            ],
+            2 => [
+                \ThriftTest\Numberz::SIX => $looney,
+            ],
+        ];
     }
 
     public function testMulti($arg0, $arg1, $arg2, array $arg3, $arg4, $arg5)
     {
-        // TODO: Implement testMulti() method.
+        $result = new \ThriftTest\Xtruct();
+        $result->string_thing = 'Hello2';
+        $result->byte_thing = $arg0;
+        $result->i32_thing = $arg1;
+        $result->i64_thing = $arg2;
+
+        return $result;
     }
 
     public function testException($arg)
     {
-        throw new \Exception($arg);
+        if ($arg === 'Xception') {
+            $exception = new \ThriftTest\Xception();
+            $exception->errorCode = 1001;
+            $exception->message = $arg;
+            throw $exception;
+        }
+
+        if ($arg === 'TException') {
+            throw new \Thrift\Exception\TException('This is a TException');
+        }
     }
 
     public function testMultiException($arg0, $arg1)
     {
-        throw new \Exception($arg0, $arg1);
+        if ($arg0 === 'Xception') {
+            $exception = new \ThriftTest\Xception();
+            $exception->errorCode = 1001;
+            $exception->message = 'This is an Xception';
+            throw $exception;
+        }
+
+        if ($arg0 === 'Xception2') {
+            $exception = new \ThriftTest\Xception2();
+            $exception->errorCode = 2002;
+            $exception->struct_thing = new \ThriftTest\Xtruct();
+            $exception->struct_thing->string_thing = 'This is an Xception2';
+            throw $exception;
+        }
+
+        $result = new \ThriftTest\Xtruct();
+        $result->string_thing = $arg1;
+
+        return $result;
     }
 
     public function testOneway($secondsToSleep)
     {
-        sleep($secondsToSleep);
+        usleep($secondsToSleep * 300000);
     }
 }
diff --git a/test/php/Makefile.am b/test/php/Makefile.am
index 60a63cf..9aefa9d 100644
--- a/test/php/Makefile.am
+++ b/test/php/Makefile.am
@@ -21,13 +21,12 @@
 	$(THRIFT) --gen php ../ThriftTest.thrift
 	$(THRIFT) --gen php:inlined ../ThriftTest.thrift
 	$(MKDIR_P) gen-php-classmap
-	$(THRIFT) -out gen-php-classmap --gen php:classmap ../ThriftTest.thrift
+	$(THRIFT) -out gen-php-classmap --gen php:classmap,server,rest ../ThriftTest.thrift
 
 php_ext_dir:
 	mkdir -p php_ext_dir
-	ln -s ../../../lib/php/src/ext/thrift_protocol/modules/thrift_protocol.so php_ext_dir/
-	ln -s "$$(php-config --extension-dir)/json.so" php_ext_dir/
-	ln -s "$$(php-config --extension-dir)/sockets.so" php_ext_dir/
+	ln -sf ../../../lib/php/src/ext/thrift_protocol/modules/thrift_protocol.so php_ext_dir/
+	ln -sf "$$(php-config --extension-dir)/sockets.so" php_ext_dir/
 
 precross: stubs php_ext_dir
 
diff --git a/test/php/TestServer.php b/test/php/TestServer.php
index 3b01752..4afb5d0 100644
--- a/test/php/TestServer.php
+++ b/test/php/TestServer.php
@@ -4,6 +4,14 @@
 
 require_once __DIR__ . '/../../vendor/autoload.php';
 
+class TBinaryProtocolAcceleratedFactory implements \Thrift\Factory\TProtocolFactory
+{
+    public function getProtocol($trans)
+    {
+        return new \Thrift\Protocol\TBinaryProtocolAccelerated($trans, false, true);
+    }
+}
+
 $opts = getopt(
     'h::',
     [
@@ -30,7 +38,7 @@
       --server-type=arg (simple)   type of server, "simple", "thread-pool",
                                    "threaded", or "nonblocking"
       --transport=arg (buffered)   transport: buffered, framed, http, anonpipe, zlib
-      --protocol=arg (binary)      protocol: binary, compact, header, json
+      --protocol=arg (binary)      protocol: binary, compact, json, accel
       --multiplex                  Add TMultiplexedProtocol service name "ThriftTest"
       --abstract-namespace         Create the domain socket in the Abstract Namespace
                                    (no connection with filesystem pathnames)
@@ -45,10 +53,11 @@
 
 $port = $opts['port'] ?? 9090;
 $transport = $opts['transport'] ?? 'buffered';
+$protocol = $opts['protocol'] ?? 'binary';
 
 
 $loader = new Thrift\ClassLoader\ThriftClassLoader();
-$loader->registerDefinition('ThriftTest', __DIR__ . '/../../lib/php/test/Resources/packages/phpcm');
+$loader->registerDefinition('ThriftTest', __DIR__ . '/gen-php-classmap');
 $loader->register();
 
 $sslOptions = \stream_context_create(
@@ -70,6 +79,28 @@
         $serverTransportFactory = new \Thrift\Factory\TTransportFactory();
 }
 
+switch ($protocol) {
+    case 'binary':
+        $protocolFactory = new \Thrift\Factory\TBinaryProtocolFactory(false, true);
+        break;
+    case 'accel':
+        if (!function_exists('thrift_protocol_write_binary')) {
+            fwrite(STDERR, "Acceleration extension is not loaded\n");
+            exit(1);
+        }
+        $protocolFactory = new TBinaryProtocolAcceleratedFactory();
+        break;
+    case 'compact':
+        $protocolFactory = new \Thrift\Factory\TCompactProtocolFactory();
+        break;
+    case 'json':
+        $protocolFactory = new \Thrift\Factory\TJSONProtocolFactory();
+        break;
+    default:
+        fwrite(STDERR, "--protocol must be one of {binary|compact|json|accel}\n");
+        exit(1);
+}
+
 $serverTransport = new \Thrift\Server\TServerSocket('localhost', $port);
 $handler = new Handler();
 $processor = new ThriftTest\ThriftTestProcessor($handler);
@@ -79,8 +110,8 @@
     $serverTransport,
     $serverTransportFactory,
     $serverTransportFactory,
-    new \Thrift\Factory\TBinaryProtocolFactory(),
-    new \Thrift\Factory\TBinaryProtocolFactory()
+    $protocolFactory,
+    $protocolFactory
 );
 
 echo "Starting the Test server...\n";
diff --git a/test/php/test_php.ini b/test/php/test_php.ini
index 5eecb32..b135e74 100644
--- a/test/php/test_php.ini
+++ b/test/php/test_php.ini
@@ -1,3 +1,2 @@
 ;extension=thrift_protocol.so
-;extension=json.so
 ;extension=sockets.so