$result = $handler->getAllIds("users"); var_dump($result); // 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) {
/** * Try to create and delete an edge with wrong encoding * We expect an exception here: * * @expectedException \triagens\ArangoDb\ClientException */ public function testCreateAndDeleteEdgeWithWrongEncoding() { $connection = $this->connection; $this->collection; $edgeCollection = $this->edgeCollection; $this->collectionHandler; $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(); $isoValue = iconv("UTF-8", "ISO-8859-1//TRANSLIT", "knowsü"); $edgeDocument->set('label', $isoValue); $edgeDocumentId = $edgeDocumentHandler->saveEdge($edgeCollection->getId(), $documentHandle1, $documentHandle2, $edgeDocument); // $resultingDocument = $documentHandler->get($edgeCollection->getId(), $edgeDocumentId); $resultingEdge = $edgeDocumentHandler->get($edgeCollection->getId(), $edgeDocumentId); $resultingAttribute = $resultingEdge->label; $this->assertTrue($resultingAttribute === 'knows', 'Attribute set on the Edge is different from the one retrieved!'); $edgesQuery1Result = $edgeDocumentHandler->edges($edgeCollection->getId(), $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!"); $resultingEdge->set('label', 'knows not'); $documentHandler->update($resultingEdge); $resultingEdge = $edgeDocumentHandler->get($edgeCollection->getId(), $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); // On ArangoDB 1.0 deleting a vertex doesn't delete the associated edge. Caution! $edgeDocumentHandler->delete($resultingEdge); }