/**
  * Try to create and delete an edge
  */
 public function testCreateAndDeleteEdge()
 {
     $connection = $this->connection;
     $edgeCollection = $this->edgeCollection;
     $document1 = new Document();
     $document2 = new Document();
     $documentHandler = new DocumentHandler($connection);
     $edgeDocument = new Edge();
     $edgeDocumentHandler = new EdgeHandler($connection);
     $document1->someAttribute = 'someValue1';
     $document2->someAttribute = 'someValue2';
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document1);
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document2);
     $documentHandle1 = $document1->getHandle();
     $documentHandle2 = $document2->getHandle();
     $edgeDocument->set('label', 'knows');
     $edgeDocumentId = $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, $edgeDocument);
     $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, array('label' => 'knows (but created using an array instead of an edge object)'));
     $resultingDocument = $documentHandler->get($edgeCollection->getName(), $edgeDocumentId);
     $resultingEdge = $edgeDocumentHandler->get($edgeCollection->getName(), $edgeDocumentId);
     $this->assertInstanceOf('triagens\\ArangoDb\\Edge', $resultingEdge);
     $resultingAttribute = $resultingEdge->label;
     $this->assertTrue($resultingAttribute === 'knows', 'Attribute set on the Edge is different from the one retrieved!');
     $edgesQuery1Result = $edgeDocumentHandler->edges($edgeCollection->getName(), $documentHandle1, 'out');
     $this->assertEquals(2, count($edgesQuery1Result));
     $statement = new Statement($connection, array("query" => '', "count" => true, "batchSize" => 1000, "sanitize" => true));
     $statement->setQuery('FOR p IN PATHS(ArangoDBPHPTestSuiteTestCollection01, ArangoDBPHPTestSuiteTestEdgeCollection01, "outbound")  RETURN p');
     $cursor = $statement->execute();
     $result = $cursor->current();
     $this->assertInstanceOf('triagens\\ArangoDb\\Document', $result, "IN PATHS statement did not return a document object!");
     $resultingDocument->set('label', 'knows not');
     $documentHandler->update($resultingDocument);
     $resultingEdge = $documentHandler->get($edgeCollection->getName(), $edgeDocumentId);
     $resultingAttribute = $resultingEdge->label;
     $this->assertTrue($resultingAttribute === 'knows not', 'Attribute "knows not" set on the Edge is different from the one retrieved (' . $resultingAttribute . ')!');
     $documentHandler->delete($document1);
     $documentHandler->delete($document2);
     // In ArangoDB deleting a vertex doesn't delete the associated edge, unless we're using the graph module. Caution!
     $edgeDocumentHandler->delete($resultingEdge);
 }
 /**
  * Try to create and delete a document using a defined key
  */
 public function testCreateAndDeleteDocumentUsingDefinedKeyWithArrayAndSaveOnly()
 {
     $connection = $this->connection;
     $collection = $this->collection;
     $documentHandler = new DocumentHandler($connection);
     $documentArray = array('someAttribute' => 'someValue', '_key' => 'frank01');
     $documentId = $documentHandler->save($collection->getName(), $documentArray);
     $resultingDocument = $documentHandler->get($collection->getName(), $documentId);
     $resultingAttribute = $resultingDocument->someAttribute;
     $resultingKey = $resultingDocument->getKey();
     $this->assertTrue($resultingAttribute === 'someValue', 'Resulting Attribute should be "someValue". It\'s :' . $resultingAttribute);
     $this->assertTrue($resultingKey === 'frank01', 'Resulting Attribute should be "someValue". It\'s :' . $resultingKey);
     $documentHandler->deleteById($collection->getName(), $documentId);
 }
    // create another new document
    $user = new Document();
    $user->set("name", "j-lo");
    $user->level = 1;
    $user->vists = array(1, 2, 3);
    $id = $handler->save("users", $user);
    var_dump("CREATED A NEW DOCUMENT WITH ID: ", $id);
    // get this document from the server
    $userFromServer = $handler->getById("users", $id);
    var_dump($userFromServer);
    // update this document
    $userFromServer->nonsense = "hihi";
    unset($userFromServer->name);
    $result = $handler->update($userFromServer);
    var_dump($result);
    // get the updated document back
    $result = $handler->get("users", $id);
    var_dump($result);
    // delete the document
    $result = $handler->deleteById("users", $id);
    var_dump($result);
    // check if a document exists
    $result = $handler->has("users", "foobar123");
    var_dump($result);
} catch (ConnectException $e) {
    print $e . PHP_EOL;
} catch (ServerException $e) {
    print $e . PHP_EOL;
} catch (ClientException $e) {
    print $e . PHP_EOL;
}