コード例 #1
0
ファイル: ClientTest.php プロジェクト: thebennos/php-client
 public function testSendWithoutBodyTransportLayerException()
 {
     $method = 'GET';
     $index = 'test-index';
     $type = 'test-type';
     $action = 'test-action';
     $divider = ClientInterface::PATH_DIVIDER;
     $path = $index . $divider . $type . $divider . $action;
     $transportLayerExceptionMsg = 'tle msg';
     //request
     $request = $this->getMockBuilder('Elastification\\Client\\Request\\RequestInterface')->getMock();
     $request->expects($this->exactly(2))->method('getMethod')->will($this->returnValue($method));
     $request->expects($this->exactly(2))->method('getIndex')->will($this->returnValue($index));
     $request->expects($this->exactly(2))->method('getType')->will($this->returnValue($type));
     $request->expects($this->exactly(2))->method('getAction')->will($this->returnValue($action));
     $request->expects($this->once())->method('getBody')->will($this->returnValue(null));
     //transport
     $transportRequest = $this->getMockBuilder('Elastification\\Client\\Transport\\TransportRequestInterface')->getMock();
     $transportRequest->expects($this->once())->method('setPath')->with($this->equalTo($path));
     $this->transport->expects($this->once())->method('createRequest')->with($this->equalTo($method))->willReturn($transportRequest);
     $this->transport->expects($this->once())->method('send')->with($this->identicalTo($transportRequest))->willThrowException(new TransportLayerException($transportLayerExceptionMsg));
     try {
         /** @noinspection PhpParamsInspection */
         $this->client->send($request);
     } catch (ClientException $exception) {
         $this->assertSame($transportLayerExceptionMsg, $exception->getMessage());
         return;
     }
     $this->fail();
 }
コード例 #2
0
 /**
  * @throws \Elastification\Client\Exception\ClientException
  * @throws \Elastification\Client\Exception\RequestException
  * @author Mario Mueller
  */
 public function testThriftConnection()
 {
     $thriftTransport = new ThriftTransport($this->thriftClient);
     $requestManager = new RequestManager();
     $client = new Client($thriftTransport, $requestManager, ClientInterface::ELASTICSEARCH_VERSION_1_3_X);
     $serializer = new NativeJsonSerializer();
     $createDocumentRequest = new CreateDocumentRequest(self::INDEX, self::TYPE, $serializer, ['assoc' => true]);
     $createDocumentRequest->setBody(array('name' => 'test' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)));
     /** @var CreateUpdateDocumentResponse $response */
     $timeStart = microtime(true);
     $response = $client->send($createDocumentRequest);
     echo 'createDocument: ' . (microtime(true) - $timeStart) . 's' . PHP_EOL;
     $this->assertSame(self::INDEX, $response->getIndex());
     $this->assertSame(self::TYPE, $response->getType());
     $this->assertSame(1, $response->getVersion());
     $this->assertTrue($response->isOk());
     $this->assertTrue(strlen($response->getId()) > 5);
 }