/**
  * Testing That the server closes the session
  *
  * @expectedException \Brightzone\GremlinDriver\ServerException
  *
  * @return void
  */
 public function testSessionClose()
 {
     $db = new Connection(['host' => 'localhost', 'port' => 8182, 'graph' => 'graph', 'username' => $this->username, 'password' => $this->password]);
     $message = $db->open();
     $this->assertNotEquals($message, FALSE, 'Failed to connect to db');
     $result = $db->send('cal = 5+5', 'session', 'eval');
     $sessionUid = $db->getSession();
     $this->assertEquals($result[0], 10, 'Script response message is not the right type. (Maybe it\'s an error)');
     //check it's a session script reply
     $result = $db->send('cal', 'session', 'eval');
     $this->assertEquals($result[0], 10, 'Script response message is not the right type. (Maybe it\'s an error)');
     //check it's a session script reply
     //check disconnection
     try {
         $db->close();
     } catch (\Exception $e) {
         $this->fail("Close shouldn't throw an exception");
     }
     $this->assertFALSE($db->isConnected(), 'Despite not throwing errors, Socket connection is established');
     $this->assertFALSE($db->inTransaction(), 'Despite closing, transaction not closed');
     $db2 = new Connection(['host' => 'localhost', 'port' => 8182, 'graph' => 'graph', 'username' => $this->username, 'password' => $this->password]);
     $message = $db2->open();
     $this->assertNotEquals($message, FALSE, 'Failed to connect to db');
     $msg = new Message();
     $msg->registerSerializer('\\Brightzone\\GremlinDriver\\Serializers\\Json');
     $msg->gremlin = 'cal';
     $msg->op = 'eval';
     $msg->processor = 'session';
     $msg->setArguments(['session' => $sessionUid]);
     $result = $db2->send($msg);
     // should throw an error as this should be next session
     $this->fail("Second request should have failed and this assert never run");
 }
 /**
  * Testing Example 5
  *
  * @return void
  */
 public function testExample5()
 {
     $message = new Message();
     $message->gremlin = 'g.V()';
     $message->op = 'eval';
     $message->processor = '';
     $message->setArguments(['language' => 'gremlin-groovy']);
     $message->registerSerializer('\\Brightzone\\GremlinDriver\\Serializers\\Json');
     $db = new Connection();
     $db->open();
     $db->send($message);
     //do something with result
     $db->close();
 }
 /**
  * Builds an authentication message when challenged by the server
  *
  * @return void
  */
 protected function authenticate()
 {
     $msg = new Message();
     $msg->op = "authentication";
     $msg->processor = "";
     $msg->setArguments(['sasl' => base64_encode(utf8_encode("" . trim($this->username) . "" . trim($this->password)))]);
     $msg->registerSerializer(new Json());
     return $this->send($msg);
 }