Ejemplo n.º 1
0
 /**
  * Test rersponse serialization
  */
 public function testSerializeResponse()
 {
     $factory = new GuzzleMessageFactory();
     $serializer = new HttpDataSerializer($factory, new GuzzleStreamFactory());
     $response = $factory->createResponse(200, null, ['Content-type' => 'application/json'], 'Foo');
     $string = $serializer->serialize($response);
     static::assertEquals("RESPONSE\r\n" . "Content-type: application/json\r\n" . "\r\n" . 'Foo', $string);
 }
Ejemplo n.º 2
0
 /**
  * @throws \Exception
  */
 public function testOutboundEnqueue()
 {
     $messageFactory = new GuzzleMessageFactory();
     $request = $messageFactory->createRequest('GET', 'http://example.com');
     $httpClient = $this->getMockForAbstractClass(HttpClient::class);
     $httpClient->expects(static::exactly(2))->method('sendRequest')->willReturnCallback(function (RequestInterface $req) use($request) {
         static $it = 0;
         $it++;
         switch ($it) {
             case 1:
                 throw new TransferException();
             case 2:
                 \PHPUnit_Framework_Assert::assertEquals($request->getUri(), $req->getUri());
                 return $this->getMockForAbstractClass(ResponseInterface::class);
         }
     });
     /** @var HttpClient $httpClient */
     $storage = new DoctrineCacheStorage(new ArrayCache());
     $gw = new HttpGateway('foo', $storage, $httpClient, $messageFactory, new GuzzleStreamFactory());
     $defaultResponse = $this->getMockForAbstractClass(ResponseInterface::class);
     /** @var ResponseInterface $defaultResponse */
     $gw->setInboundPolicy(new DefaultInboundPolicy($defaultResponse));
     $gw->setOutboundPolicy(new DefaultOutboundPolicy(1));
     $response = $gw->sendRequest($request);
     static::assertSame($defaultResponse, $response);
     sleep(2);
     $gw->runQueue();
 }
Ejemplo n.º 3
0
 public function version()
 {
     $message = new GuzzleMessageFactory();
     $request = $message->createRequest('GET', $this->url . 'version');
     $result = $this->adapter->sendRequest($request);
     return new Version($result);
 }