XmlRpcSpec.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace spec\Supervisor\Connector;
  3. use fXmlRpc\ClientInterface;
  4. use fXmlRpc\Exception\ResponseException;
  5. use PhpSpec\ObjectBehavior;
  6. class XmlRpcSpec extends ObjectBehavior
  7. {
  8. function let(ClientInterface $client)
  9. {
  10. $this->beConstructedWith($client);
  11. }
  12. function it_is_initializable()
  13. {
  14. $this->shouldHaveType('Supervisor\Connector\XmlRpc');
  15. }
  16. function it_is_a_conncetor()
  17. {
  18. $this->shouldImplement('Supervisor\Connector');
  19. }
  20. function it_calls_a_method(ClientInterface $client)
  21. {
  22. $client->call('namespace.method', [])->willReturn('response');
  23. $this->call('namespace', 'method')->shouldReturn('response');
  24. }
  25. function it_throws_an_exception_when_the_call_fails(ClientInterface $client)
  26. {
  27. $e = ResponseException::fault([
  28. 'faultString' => 'Invalid response',
  29. 'faultCode' => 100,
  30. ]);
  31. $client->call('namespace.method', [])->willThrow($e);
  32. $this->shouldThrow('Supervisor\Exception\Fault')->duringCall('namespace', 'method');
  33. }
  34. function it_throws_a_known_exception_when_proper_fault_returned(ClientInterface $client)
  35. {
  36. $e = ResponseException::fault([
  37. 'faultString' => 'UNKNOWN_METHOD',
  38. 'faultCode' => 1,
  39. ]);
  40. $client->call('namespace.method', [])->willThrow($e);
  41. $this->shouldThrow('Supervisor\Exception\Fault\UnknownMethod')->duringCall('namespace', 'method');
  42. }
  43. }