/** * test for replacing a edge using replace() */ public function testReplaceEdge() { $connection = $this->connection; $edgeHandler = new EdgeHandler($connection); $edgeCollection = $this->edgeCollection; $document1 = new Document(); $document2 = new Document(); $documentHandler = new DocumentHandler($connection); $edgeDocument = new Edge(); $document1->someAttribute = 'someValue1'; $document2->someAttribute = 'someValue2'; $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document1); $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document2); $documentHandle1 = $document1->getHandle(); $documentHandle2 = $document2->getHandle(); $edgeDocument->set('label', null); $edgeDocument->set('labelt', "as"); $edgeId = $edgeHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, $edgeDocument); $this->assertTrue(is_numeric($edgeId), 'Did not return an id!'); $edgePutDocument = new Edge(); $edgePutDocument->set('_id', $edgeDocument->getHandle()); $edgePutDocument->set('_rev', $edgeDocument->getRevision()); $edgePutDocument->set('labels', "as"); $result = $edgeHandler->replace($edgePutDocument); $this->assertTrue($result); $resultingEdge = $edgeHandler->get($edgeCollection->getId(), $edgeId); $this->assertObjectHasAttribute('_id', $resultingEdge, '_id field should exist, empty or with an id'); $this->assertTrue($resultingEdge->label == null, 'Should be :null, is: ' . $resultingEdge->label); $this->assertTrue($resultingEdge->labelt == null, 'Should be :null, is: ' . $resultingEdge->labelt); $this->assertTrue($resultingEdge->labels == "as"); $response = $edgeHandler->delete($resultingEdge); $this->assertTrue($response, 'Delete should return true!'); }
/** * 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); }