public function testCommitBatch_AddToIndex_NoEntitiesExist_Success_ReturnsTrue()
 {
     $nodeA = new Node($this->client);
     $nodeB = new Node($this->client);
     $rel = new Relationship($this->client);
     $rel->setType('TEST')->setStartNode($nodeA)->setEndNode($nodeB);
     $index = new Index($this->client, Index::TypeRelationship, 'indexname');
     $request = array(array('id' => 2, 'method' => 'POST', 'to' => '/node', 'body' => null), array('id' => 3, 'method' => 'POST', 'to' => '/node', 'body' => null), array('id' => 1, 'method' => 'POST', 'to' => '{2}/relationships', 'body' => array('to' => '{3}', 'type' => 'TEST')), array('id' => 0, 'method' => 'POST', 'to' => '/index/relationship/indexname', 'body' => array('key' => 'somekey', 'value' => 'somevalue', 'uri' => '{1}')));
     $return = array('code' => 200, 'data' => array(array('id' => 2, 'location' => 'http://foo:1234/db/data/node/123'), array('id' => 3, 'location' => 'http://foo:1234/db/data/node/456'), array('id' => 1, 'location' => 'http://foo:1234/db/data/relationship/789'), array('id' => 0)));
     $this->batch->addToIndex($index, $rel, 'somekey', 'somevalue');
     $this->setupTransportExpectation($request, $this->returnValue($return));
     $result = $this->client->commitBatch($this->batch);
     $this->assertTrue($result);
     $this->assertEquals(123, $nodeA->getId());
     $this->assertEquals(456, $nodeB->getId());
     $this->assertEquals(789, $rel->getId());
 }
Exemplo n.º 2
0
 public function testSaveRelationship_CreateTransportError_ThrowsException()
 {
     $data = array('data' => array('foo' => 'bar', 'baz' => 'qux'), 'to' => $this->endpoint . '/node/456', 'type' => 'FOOTYPE');
     $start = new Node($this->client);
     $start->setId(123);
     $end = new Node($this->client);
     $end->setId(456);
     $rel = new Relationship($this->client);
     $rel->setType('FOOTYPE')->setStartNode($start)->setEndNode($end)->setProperties($data['data']);
     $this->transport->expects($this->once())->method('post')->with('/node/123/relationships', $data)->will($this->returnValue(array('code' => 400)));
     $this->setExpectedException('Everyman\\Neo4j\\Exception');
     $this->client->saveRelationship($rel);
 }
Exemplo n.º 3
0
 /**
  * Fill a relationship with data
  *
  * @param Relationship $rel
  * @param array $data
  * @return Relationship
  */
 public function populateRelationship(Relationship $rel, $data)
 {
     $rel->useLazyLoad(false);
     $rel->setProperties($data['data']);
     $rel->setType($data['type']);
     $rel->setStartNode($this->getNodeFromUri($data['start']));
     $rel->setEndNode($this->getNodeFromUri($data['end']));
     return $rel;
 }
 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());
 }