コード例 #1
0
 public function testCommitBatch_DeleteNode_Success_ReturnsTrue()
 {
     $node = new Node($this->client);
     $node->setId(123);
     $this->client->getEntityCache()->setCachedEntity($node);
     $request = array(array('id' => 0, 'method' => 'DELETE', 'to' => '/node/123'));
     $return = array('code' => 200, 'data' => array(array('id' => 0)));
     $this->batch->delete($node);
     $this->setupTransportExpectation($request, $this->returnValue($return));
     $result = $this->client->commitBatch($this->batch);
     $this->assertTrue($result);
     $this->assertFalse($this->client->getEntityCache()->getCachedEntity(123, 'node'));
 }
コード例 #2
0
 /**
  * @param Node $node
  *
  * @return $this
  */
 public function addNode(Node $node)
 {
     if (isset($this->idList[$node->id])) {
         /**
          * @todo -> fix this behavior so the get last is working again
          */
         $node->setId($this->getNextPossibleIdInContext($node));
     }
     // add to the keylist for iterations
     if (isset($this->keyList[$node->key])) {
         $this->keyList[$node->key]->push($node);
     } else {
         $this->keyList[$node->key] = new \SplDoublyLinkedList();
         $this->keyList[$node->key]->push($node);
     }
     $this->list[$node->key] = $node;
     $this->idList[$node->id] = $node;
     return $this;
 }
コード例 #3
0
 public function testSerialize_KeepsStartEndAndType()
 {
     $expectedStart = new Node($this->client);
     $expectedStart->setId(123);
     $expectedEnd = new Node($this->client);
     $expectedEnd->setId(456);
     $this->relationship->setType($this->type)->setStartNode($expectedStart)->setEndNode($expectedEnd);
     // serialize and unserialize
     $data = serialize($this->relationship);
     $rel = unserialize($data);
     // we must reset the client
     $rel->setClient($this->client);
     $start = $rel->getStartNode();
     $end = $rel->getEndNode();
     $this->assertEquals($this->relationship, $rel, 'The relationship is restored by unserialize');
     $this->assertEquals($expectedStart, $start, 'The start node should be restored by unserialize');
     $this->assertEquals($expectedEnd, $end, 'The end node should be restored by unserialize');
     $this->assertEquals($this->type, $rel->getType(), 'The type should be restored by unserialize');
     $this->assertEquals($this->client, $start->getClient(), 'The client should be restored in the start node by setClient on the relation');
     $this->assertEquals($this->client, $end->getClient(), 'The client should be restored in the end node by setClient on the relation');
 }
コード例 #4
0
 public function testRemoveFromIndex_RelationshipTypeMismatch_ThrowsException()
 {
     $index = new Index($this->client, Index::TypeRelationship, 'indexname');
     $node = new Node($this->client);
     $node->setId(123);
     $this->setExpectedException('\\Sgpatil\\Orientphp\\Exception');
     $this->client->removeFromIndex($index, $node);
 }
コード例 #5
0
 public function testGetNodeRelationships_Relationships_ReturnsArray()
 {
     $node = new Node($this->client);
     $node->setId(123);
     $types = array('FOOTYPE', 'BARTYPE');
     $dir = Relationship::DirectionOut;
     $data = array(array("self" => "http://localhost:7474/db/data/relationship/56", "start" => "http://localhost:7474/db/data/node/123", "end" => "http://localhost:7474/db/data/node/93", "type" => "KNOWS", "data" => array('foo' => 'bar', 'baz' => 'qux')), array("self" => "http://localhost:7474/db/data/relationship/834", "start" => "http://localhost:7474/db/data/node/32", "end" => "http://localhost:7474/db/data/node/123", "type" => "LOVES", "data" => array('bar' => 'foo', 'qux' => 'baz')));
     $this->transport->expects($this->once())->method('get')->with('/node/123/relationships/out/FOOTYPE&BARTYPE')->will($this->returnValue(array('code' => 200, 'data' => $data)));
     $result = $this->client->getNodeRelationships($node, $types, $dir);
     $this->assertEquals(2, count($result));
     $this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[0]);
     $this->assertEquals(56, $result[0]->getId());
     $this->assertEquals($data[0]['data'], $result[0]->getProperties());
     $this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getStartNode());
     $this->assertEquals(123, $result[0]->getStartNode()->getId());
     $this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[0]->getEndNode());
     $this->assertEquals(93, $result[0]->getEndNode()->getId());
     $this->assertInstanceOf('Everyman\\Neo4j\\Relationship', $result[1]);
     $this->assertEquals(834, $result[1]->getId());
     $this->assertEquals($data[1]['data'], $result[1]->getProperties());
     $this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1]->getStartNode());
     $this->assertEquals(32, $result[1]->getStartNode()->getId());
     $this->assertInstanceOf('Everyman\\Neo4j\\Node', $result[1]->getEndNode());
     $this->assertEquals(123, $result[1]->getEndNode()->getId());
 }
コード例 #6
0
 public function testDeleteNode_Failure_NodeRemainsInCache()
 {
     $nodeId = 123;
     $node = new Node($this->client);
     $node->setId($nodeId);
     $this->transport->expects($this->once())->method('delete')->with('/node/' . $nodeId)->will($this->returnValue(array('code' => '400')));
     $this->cache->set("node-{$nodeId}", $node);
     try {
         $this->client->deleteNode($node);
         $this->fail();
     } catch (Exception $e) {
         $this->assertSame($node, $this->cache->get("node-{$nodeId}"));
     }
 }
コード例 #7
0
 public function testImplicitBatch_StartBatch_CloseBatch_ExpectedBatchRequest()
 {
     $startNode = new Node($this->client);
     $endNode = new Node($this->client);
     $endNode->setId(456)->useLazyLoad(false);
     $rel = new Relationship($this->client);
     $rel->setType('TEST')->setStartNode($startNode)->setEndNode($endNode);
     $deleteNode = new Node($this->client);
     $deleteNode->setId(987);
     $deleteRel = new Relationship($this->client);
     $deleteRel->setId(321);
     $addIndexNode = new Node($this->client);
     $addIndexNode->setId(654);
     $removeIndexNode = new Node($this->client);
     $removeIndexNode->setId(209);
     $index = new Index($this->client, Index::TypeNode, 'indexname');
     $request = array(array('id' => 0, 'method' => 'POST', 'to' => '/node', 'body' => null), array('id' => 1, 'method' => 'PUT', 'to' => '/node/456/properties', 'body' => array()), array('id' => 2, 'method' => 'POST', 'to' => '{0}/relationships', 'body' => array('to' => $this->endpoint . '/node/456', 'type' => 'TEST')), array('id' => 3, 'method' => 'DELETE', 'to' => '/node/987'), array('id' => 4, 'method' => 'DELETE', 'to' => '/relationship/321'), array('id' => 5, 'method' => 'POST', 'to' => '/index/node/indexname', 'body' => array('key' => 'addkey', 'value' => 'addvalue', 'uri' => $this->endpoint . '/node/654')), array('id' => 6, 'method' => 'DELETE', 'to' => '/index/node/indexname/removekey/removevalue/209'));
     $return = array('code' => 200, 'data' => array(array('id' => 0, 'location' => 'http://foo:1234/db/data/node/123'), array('id' => 1), array('id' => 2, 'location' => 'http://foo:1234/db/data/relationship/789'), array('id' => 3), array('id' => 4), array('id' => 5), array('id' => 6)));
     $this->setupTransportExpectation($request, $this->returnValue($return));
     $batch = $this->client->startBatch();
     $this->assertInstanceOf('Sgpatil\\Orientphp\\Batch', $batch);
     $startNode->save();
     $endNode->save();
     $rel->save();
     $deleteNode->delete();
     $deleteRel->delete();
     $index->add($addIndexNode, 'addkey', 'addvalue');
     $index->remove($removeIndexNode, 'removekey', 'removevalue');
     $this->assertTrue($this->client->commitBatch());
     $this->assertEquals(789, $rel->getId());
     $this->assertEquals(123, $startNode->getId());
 }
コード例 #8
0
ファイル: GeoffTest.php プロジェクト: MobilityMaster/neo4jphp
    public function testDump_PathsGiven_FileDescriptor_ReturnsDescriptor()
    {
        $nodeA = new Node($this->client);
        $nodeA->setId(123)->setProperties(array('foo' => 'bar', 'baz' => 'qux'));
        $nodeB = new Node($this->client);
        $nodeB->setId(456)->setProperties(array('somekey' => 'somevalue'));
        $relA = new Relationship($this->client);
        $relA->setId(987)->setType('TEST')->setStartNode($nodeA)->setEndNode($nodeB)->setProperties(array('anotherkey' => 'anothervalue'));
        $path = new Path();
        $path->appendNode($nodeA);
        $path->appendNode($nodeB);
        $path->appendRelationship($relA);
        $expected = <<<GEOFF
(123)\t{"foo":"bar","baz":"qux"}
(456)\t{"somekey":"somevalue"}
(123)-[987:TEST]->(456)\t{"anotherkey":"anothervalue"}

GEOFF;
        $handle = fopen('data:text/plain,', 'w+');
        $resultHandle = $this->geoff->dump($path, $handle);
        self::assertSame($handle, $resultHandle);
        self::assertEquals($expected, stream_get_contents($resultHandle, -1, 0));
    }
コード例 #9
0
 public function testGetPaths_TransportFails_ThrowsException()
 {
     $startNode = new Node($this->client);
     $startNode->setId(123);
     $endNode = new Node($this->client);
     $endNode->setId(456);
     $finder = new PathFinder($this->client);
     $finder->setType('FOOTYPE')->setDirection(Relationship::DirectionOut)->setMaxDepth(3)->setStartNode($startNode)->setEndNode($endNode);
     $this->transport->expects($this->any())->method('post')->will($this->returnValue(array('code' => 400)));
     $this->setExpectedException('\\Everyman\\Neo4j\\Exception');
     $this->client->getPaths($finder);
 }
コード例 #10
0
 public function testRemoveLabels_NoLabelsGiven_ThrowsException()
 {
     $node = new Node($this->client);
     $node->setId(123);
     $this->transport->expects($this->never())->method('post');
     $this->setExpectedException('InvalidArgumentException', 'No labels');
     $this->client->removeLabels($node, array());
 }
コード例 #11
0
 public function testGetNodeRelationships_UrlCharactersInTypeName_EncodesCorrectly()
 {
     $node = new Node($this->client);
     $node->setId(123);
     $types = array('FOO\\TYPE', 'BAR?TYPE', 'BAZ/TYPE');
     $this->transport->expects($this->once())->method('get')->with('/node/123/relationships/all/FOO%5CTYPE&BAR%3FTYPE&BAZ%2FTYPE')->will($this->returnValue(array('code' => 200, 'data' => array())));
     $result = $this->client->getNodeRelationships($node, $types);
 }
コード例 #12
0
ファイル: BatchTest.php プロジェクト: MobilityMaster/neo4jphp
 public function testRemoveFromIndex_Index_ReturnsIntegerOperationIndex()
 {
     $nodeA = new Node($this->client);
     $nodeA->setId(123);
     $nodeB = new Node($this->client);
     $nodeB->setId(456);
     $index = new Index($this->client, Index::TypeNode, 'indexname');
     $this->assertEquals(0, $this->batch->removeFromIndex($index, $nodeA, 'somekey', 'somevalue'));
     $this->assertEquals(1, $this->batch->removeFromIndex($index, $nodeA, 'otherkey'));
     $this->assertEquals(2, $this->batch->removeFromIndex($index, $nodeA));
     $this->assertEquals(3, $this->batch->removeFromIndex($index, $nodeB, 'diffkey', 'diffvalue'));
 }
コード例 #13
0
 public function testCommitBatch_RemoveFromIndex_EntityKeyValue_Success_ReturnsTrue()
 {
     $node = new Node($this->client);
     $node->setId(123);
     $index = new Index($this->client, Index::TypeNode, 'indexname');
     $request = array(array('id' => 0, 'method' => 'DELETE', 'to' => '/index/node/indexname/somekey/somevalue/123'));
     $return = array('code' => 200, 'data' => array(array('id' => 0)));
     $this->batch->removeFromIndex($index, $node, 'somekey', 'somevalue');
     $this->setupTransportExpectation($request, $this->returnValue($return));
     $result = $this->client->commitBatch($this->batch);
     $this->assertTrue($result);
 }
コード例 #14
0
 public function testPagedTraversal_ServerReturnsError_ThrowsException()
 {
     $traversal = new Traversal($this->client);
     $traversal->setOrder(Traversal::OrderDepthFirst);
     $node = new Node($this->client);
     $node->setId(1);
     $pager = new Pager($traversal, $node, Traversal::ReturnTypeNode);
     $pager->setPageSize(1)->setLeaseTime(30);
     $this->transport->expects($this->once())->method('post')->with('/node/1/paged/traverse/node?pageSize=1&leaseTime=30', array("order" => "depth_first"))->will($this->returnValue(array("code" => 400)));
     $this->setExpectedException('Everyman\\Neo4j\\Exception');
     $result = $this->client->executePagedTraversal($pager);
 }