Exemplo n.º 1
0
 protected function setUp()
 {
     $this->serializer = $this->getMockForAbstractClass('Wookieb\\ZorroRPC\\Serializer\\ServerSerializerInterface');
     $this->transport = $this->getMockForAbstractClass('Wookieb\\ZorroRPC\\Transport\\ServerTransportInterface');
     if ($this->useFalseWaitingForResponse) {
         $this->transport->expects($this->any())->method('isWaitingForResponse')->will($this->returnValue(false));
     }
     $this->rpcTarget = $this->getMock('\\stdClass', $this->methods);
     $this->object = new Server($this->transport, $this->serializer);
     $this->object->setOnErrorCallback(function ($e) {
         throw $e;
     });
 }
Exemplo n.º 2
0
 public function testArgumentProvidedToRegisterMethodsMustBeAnArrayOfMethodInstance()
 {
     $this->setExpectedException('\\InvalidArgumentException', 'Every element of list must be instance of Method');
     $this->server->registerMethods(array('test'));
 }
Exemplo n.º 3
0
<?php

require_once '../vendor/autoload.php';
require_once './ExampleClass.php';
use Wookieb\ZorroRPC\Server\Server;
use Wookieb\ZorroRPC\Transport\ZeroMQ\ZeroMQServerTransport;
use Wookieb\ZorroRPC\Serializer\SchemalessServerSerializer;
use Wookieb\ZorroRPC\Serializer\DataFormat\JSONDataFormat;
use Wookieb\ZorroRPC\Serializer\DataFormat\PHPNativeSerializerDataFormat;
use Wookieb\ZorroRPC\Headers\Headers;
use Wookieb\ZorroRPC\Server\MethodTypes;
$transport = ZeroMQServerTransport::create('tcp://0.0.0.0:1500');
$serializer = new SchemalessServerSerializer(new JSONDataFormat());
$server = new Server($transport, $serializer);
// uncomment these lines if u would like to use php serialization format
/*
$serializer->registerDataFormat(new PHPNativeSerializerDataFormat());
$server->setDefaultHeaders(new Headers(array(
    'content-type' => 'application/vnd.php.serialized'
)));
*/
$server->registerMethod('basic', function ($what) {
    return 'hello ' . $what;
});
$server->registerMethod('serializationTest', function ($private = 'private', $protected = 'protected', $public = 'public') {
    $example = new \ExampleClass($private, $protected, $public);
    return $example;
});
$server->registerMethod('push', function ($data, \Closure $callback) {
    if (!$data) {
        throw new \InvalidArgumentException('Data cannot be empty');