[THRIFT-5757] Unit tests for php lib
Client: php
Patch: Volodymyr Panivko

This closes #2951
diff --git a/test/php/Client.php b/test/php/Client.php
new file mode 100644
index 0000000..1cd4241
--- /dev/null
+++ b/test/php/Client.php
@@ -0,0 +1,26 @@
+<?php
+
+use Thrift\Protocol\TCompactProtocol;
+use Thrift\Transport\THttpClient;
+
+error_reporting(E_ALL);
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+$loader = new Thrift\ClassLoader\ThriftClassLoader();
+$loader->registerDefinition('ThriftTest', __DIR__ . '/../../lib/php/test/Resources/packages/phpcm');
+$loader->register();
+
+
+$transport = new THttpClient('localhost', 80);
+
+$transport->setTimeoutSecs($this->timeoutSec);
+
+$transport->addHeaders($this->generateAuthHeader());
+
+$protocol = new TCompactProtocol($transport);
+
+$transport->open();
+
+$client = new \ThriftTest\ThriftTestClient($protocol);
+$client->testVoid();
diff --git a/test/php/Handler.php b/test/php/Handler.php
new file mode 100644
index 0000000..5ca06a2
--- /dev/null
+++ b/test/php/Handler.php
@@ -0,0 +1,114 @@
+<?php
+
+class Handler implements \ThriftTest\ThriftTestIf
+{
+    public function testVoid()
+    {
+        return;
+    }
+
+    public function testString($thing)
+    {
+        return $thing;
+    }
+
+    public function testBool($thing)
+    {
+        return $thing;
+    }
+
+    public function testByte($thing)
+    {
+        return $thing;
+    }
+
+    public function testI32($thing)
+    {
+        return $thing;
+    }
+
+    public function testI64($thing)
+    {
+        return $thing;
+    }
+
+    public function testDouble($thing)
+    {
+        return $thing;
+    }
+
+    public function testBinary($thing)
+    {
+        return $thing;
+    }
+
+    public function testStruct(\ThriftTest\Xtruct $thing)
+    {
+        return $thing;
+    }
+
+    public function testNest(\ThriftTest\Xtruct2 $thing)
+    {
+        return $thing;
+    }
+
+    public function testMap(array $thing)
+    {
+        return $thing;
+    }
+
+    public function testStringMap(array $thing)
+    {
+        return $thing;
+    }
+
+    public function testSet(array $thing)
+    {
+        return $thing;
+    }
+
+    public function testList(array $thing)
+    {
+        return $thing;
+    }
+
+    public function testEnum($thing)
+    {
+        return $thing;
+    }
+
+    public function testTypedef($thing)
+    {
+        return $thing;
+    }
+
+    public function testMapMap($hello)
+    {
+        return $hello;
+    }
+
+    public function testInsanity(\ThriftTest\Insanity $argument)
+    {
+        return $argument;
+    }
+
+    public function testMulti($arg0, $arg1, $arg2, array $arg3, $arg4, $arg5)
+    {
+        // TODO: Implement testMulti() method.
+    }
+
+    public function testException($arg)
+    {
+        throw new \Exception($arg);
+    }
+
+    public function testMultiException($arg0, $arg1)
+    {
+        throw new \Exception($arg0, $arg1);
+    }
+
+    public function testOneway($secondsToSleep)
+    {
+        sleep($secondsToSleep);
+    }
+}
diff --git a/test/php/TestServer.php b/test/php/TestServer.php
new file mode 100644
index 0000000..3b01752
--- /dev/null
+++ b/test/php/TestServer.php
@@ -0,0 +1,87 @@
+<?php
+
+error_reporting(E_ALL);
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+$opts = getopt(
+    'h::',
+    [
+        'port::',
+        'domain-socket::',
+        'pipe::',
+        'server-type::',
+        'transport::',
+        'protocol::',
+        'multiplex::',
+        'abstract-namespace::',
+        'ssl::',
+        'zlib::',
+        'processor-events::',
+        'workers::',
+    ]
+);
+if (isset($opts['h'])) {
+    echo <<<HELP
+      -h | --help                  produce help message
+      --port=arg (9090)            Port number to listen
+      --domain-socket=arg          Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)
+      --pipe=arg                   Windows Named Pipe (e.g. MyThriftPipe)
+      --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
+      --multiplex                  Add TMultiplexedProtocol service name "ThriftTest"
+      --abstract-namespace         Create the domain socket in the Abstract Namespace
+                                   (no connection with filesystem pathnames)
+      --ssl                        Encrypted Transport using SSL
+      --zlib                       Wrapped Transport using Zlib
+      --processor-events           processor-events
+      -n=arg | --workers=arg (=4)  Number of thread pools workers. Only valid for
+                                   thread-pool server type
+HELP;
+    exit(0);
+}
+
+$port = $opts['port'] ?? 9090;
+$transport = $opts['transport'] ?? 'buffered';
+
+
+$loader = new Thrift\ClassLoader\ThriftClassLoader();
+$loader->registerDefinition('ThriftTest', __DIR__ . '/../../lib/php/test/Resources/packages/phpcm');
+$loader->register();
+
+$sslOptions = \stream_context_create(
+    [
+        'ssl' => [
+            'verify_peer' => false,
+            'verify_peer_name' => false,
+        ],
+    ]
+);
+
+require_once __DIR__ . '/Handler.php';
+
+switch ($transport) {
+    case 'framed':
+        $serverTransportFactory = new \Thrift\Factory\TFramedTransportFactory();
+        break;
+    default:
+        $serverTransportFactory = new \Thrift\Factory\TTransportFactory();
+}
+
+$serverTransport = new \Thrift\Server\TServerSocket('localhost', $port);
+$handler = new Handler();
+$processor = new ThriftTest\ThriftTestProcessor($handler);
+
+$server = new \Thrift\Server\TSimpleServer(
+    $processor,
+    $serverTransport,
+    $serverTransportFactory,
+    $serverTransportFactory,
+    new \Thrift\Factory\TBinaryProtocolFactory(),
+    new \Thrift\Factory\TBinaryProtocolFactory()
+);
+
+echo "Starting the Test server...\n";
+$server->serve();
diff --git a/test/php/test_php.ini b/test/php/test_php.ini
index aeb67cb..5eecb32 100644
--- a/test/php/test_php.ini
+++ b/test/php/test_php.ini
@@ -1,3 +1,3 @@
-extension=thrift_protocol.so
-extension=json.so
-extension=sockets.so
+;extension=thrift_protocol.so
+;extension=json.so
+;extension=sockets.so