/** * @dataProvider getClients */ public function testSimpleMulticall(ClientInterface $client) { $this->expected = $expected = array(array('Idaho'), array('Michigan'), array('New York'), array('Tennessee')); $result = $client->multicall()->addCall('examples.getStateName', array(12))->addCall('examples.getStateName', array(22))->addCall('examples.getStateName', array(32))->addCall('examples.getStateName', array(42))->onSuccess(array($this, 'handler'))->execute(); $this->assertSame($expected, $result); $this->assertSame(4, $this->handlerInvoked); }
public function testCallingNamespaceMethodWithCustomSeparator() { $proxy = new Proxy($this->client, '_'); $this->client->expects($this->at(0))->method('call')->with('namespace_method', array(1, 2))->will($this->returnValue('namespace method return')); $this->client->expects($this->at(1))->method('call')->with('namespace_another_namespace_method', array(1, 2))->will($this->returnValue('another namespace method return')); $this->assertSame('namespace method return', $proxy->namespace->method(1, 2)); $this->assertSame('another namespace method return', $proxy->namespace->another_namespace->method(1, 2)); }
/** {@inheritdoc} */ public function execute() { $results = $this->client->call('system.multicall', [$this->calls]); foreach ($results as $index => $result) { $this->processResult($this->handlers[$index], $result); } return $results; }
/** * {@inheritdoc} */ public function call($namespace, $method, array $arguments = []) { try { return $this->client->call($namespace . '.' . $method, $arguments); } catch (ResponseException $e) { throw Fault::create($e->getFaultString(), $e->getFaultCode()); } }
/** * @dataProvider getClients */ public function testServerNotReachableViaTcpIp(ClientInterface $client) { $client->setUri('http://127.0.0.1:12345/'); try { $client->call('system.failure'); $this->fail('Exception expected'); } catch (\fXmlRpc\Exception\TcpException $e) { $this->assertInstanceOf('fXmlRpc\\Exception\\TransportException', $e); $this->assertInstanceOf('fXmlRpc\\Exception\\ExceptionInterface', $e); $this->assertInstanceOf('RuntimeException', $e); $this->assertStringStartsWith('A transport error occurred', $e->getMessage()); $this->assertSame(0, $e->getCode()); } }
public function testGlobalErrorHandler() { $this->client->expects($this->once())->method('call')->with('system.multicall', array(array(array('methodName' => 'method1', 'params' => array('arg11', 'arg12')), array('methodName' => 'method2', 'params' => array('arg21', 'arg22')))))->will($this->returnValue(array('return1', array('faultCode' => 200)))); $individualSuccessHandlerResults = array(); $individualSuccessHandler = function ($result) use(&$individualSuccessHandlerResults) { $individualSuccessHandlerResults[] = $result; }; $globalSuccessHandlerResults = array(); $globalSuccessHandler = function ($result) use(&$globalSuccessHandlerResults) { $globalSuccessHandlerResults[] = $result; }; $globalErrorHandlerResults = array(); $globalErrorHandler = function ($result) use(&$globalErrorHandlerResults) { $globalErrorHandlerResults[] = $result; }; $results = $this->multicallBuilder->addCall('method1', array('arg11', 'arg12'), $individualSuccessHandler)->addCall('method2', array('arg21', 'arg22'), $individualSuccessHandler)->onSuccess($globalSuccessHandler)->onError($globalErrorHandler)->execute(); $this->assertSame(array('return1', array('faultCode' => 200)), $results); $this->assertSame($results, $individualSuccessHandlerResults); $this->assertSame(array('return1'), $globalSuccessHandlerResults); $this->assertSame(array(array('faultCode' => 200)), $globalErrorHandlerResults); }
public function testRecordTimeIsCalled() { $this->timer->expects($this->once())->method('recordTiming')->with($this->equalTo(0, 0.1), 'method', array('arg1', 'arg2')); $this->wrapped->expects($this->once())->method('call')->with('method', array('arg1', 'arg2')); $this->decorator->call('method', array('arg1', 'arg2')); }
function it_throws_a_known_exception_when_proper_fault_returned(ClientInterface $client) { $e = ResponseException::fault(['faultString' => 'UNKNOWN_METHOD', 'faultCode' => 1]); $client->call('namespace.method', [])->willThrow($e); $this->shouldThrow('Indigo\\Supervisor\\Exception\\Fault\\UnknownMethod')->duringCall('namespace', 'method'); }
/** * @dataProvider getClients */ public function testHeaderCustomIsSent(ClientInterface $client, TransportInterface $transport) { if (in_array('xmlrpc_header', $this->disabledExtensions)) { $this->markTestSkipped('Missing system.header() call'); } if ($transport instanceof HttpTransportInterface) { $this->assertSame($transport, $transport->setHeader('X-Foo', 'Bar')); $this->assertSame('Bar', $client->call('system.header', ['x-foo']), 'X-Foo newly set'); $this->assertSame($transport, $transport->setHeaders(['X-Bar' => 'Foo'])); $this->assertSame('Foo', $client->call('system.header', ['x-bar']), 'X-Bar newly set'); $this->assertSame($transport, $transport->setHeader('X-Foo', 'Bar')); $this->assertSame('Bar', $client->call('system.header', ['x-foo']), 'X-Foo still set'); $this->assertSame($transport, $transport->setHeader('X-Foo', null)); $this->assertSame(null, $client->call('system.header', ['x-foo']), 'X-Foo unset'); $this->assertSame($transport, $transport->setHeaders(['X-Bar' => 'Foo'])); $this->assertSame('Foo', $client->call('system.header', ['x-bar']), 'X-Bar still set'); } }
public function testMulticallMethodWrapped() { $this->wrapped->expects($this->once())->method('multicall')->will($this->returnValue('m')); $this->assertSame('m', $this->decorator->multicall()); }