Esempio n. 1
0
 function setUp()
 {
     if (!self::$root) {
         $aragorn = new Entity\Person();
         $aragorn->setFirstName('Viggo');
         $aragorn->setLastName('Mortensen');
         $legolas = new Entity\Person();
         $legolas->setFirstName('Orlando');
         $legolas->setLastName('Bloom');
         $root = new Entity\Movie();
         $root->setTitle('Return of the king');
         $root->addActor($aragorn);
         $root->addActor($legolas);
         self::$root = $root;
         self::$aragorn = $aragorn;
         self::$legolas = $legolas;
         $em = $this->getEntityManager();
         $em->persist($root);
         $em->flush();
     }
 }
Esempio n. 2
0
 function testSelfReferencingNodes()
 {
     $em = $this->getEntityManager();
     $a = new Entity\Person();
     $b = new Entity\Person();
     $a->addFriend($b);
     $b->addFriend($a);
     $em->persist($a);
     $em->flush();
     $loaded = $em->find(get_class($a), $a->getId());
     $this->assertCount(1, $loaded->getFriends());
 }
 function testRelationCreationHook()
 {
     $code = null;
     $em = $this->getEntityManager();
     $em->registerEvent(Neo4j\EntityManager::RELATION_CREATE, function ($type, $start, $end) use(&$code) {
         $code = $start->getTitle() . '-' . $type . '-' . $end->getFirstName();
     });
     $movie = new Entity\Movie();
     $movie->setTitle('Terminator');
     $actor = new Entity\Person();
     $actor->setFirstName('Arnold');
     $movie->addActor($actor);
     $em->persist($movie);
     $em->flush();
     $this->assertEquals("Terminator-actor-Arnold", $code);
 }
Esempio n. 4
0
 public function testRelationRemove()
 {
     $eventManager = $this->getEventManagerWithListenerExpectations(array('prePersist' => 3, 'postPersist' => 3, 'preRelationCreate' => 1, 'postRelationCreate' => 1, 'preRelationRemove' => 1, 'postRelationRemove' => 1));
     $movie = new Entity\Movie();
     $movie->setTitle('Terminator');
     $actor = new Entity\Person();
     $actor->setFirstName('Arnold');
     $movie->addActor($actor);
     $this->em->setEventManager($eventManager);
     $this->em->persist($movie);
     $this->em->flush();
     $movie = $this->em->find(get_class($movie), $movie->getId());
     $actor = $movie->getActors()->first();
     $movie->removeActor($actor);
     $this->em->persist($movie);
     $this->em->flush();
 }