public function testLazyLoadedEntitiesAreManagedForRemoval()
 {
     $this->clearDb();
     $michal = new User('michal');
     $daniela = new User('daniela');
     $city = new City('London');
     $michal->setCity($city);
     $daniela->setCity($city);
     $this->em->persist($city);
     $this->em->persist($michal);
     $this->em->persist($daniela);
     $this->em->flush();
     $this->assertGraphExist('(m:User {login:"******"})-[:LIVES_IN {since:123}]->(c:City {name:"London"})<-[:LIVES_IN {since:123}]-(d:User {login:"******"})');
     $this->em->clear();
     /** @var City $london */
     $london = $this->em->getRepository(City::class)->findOneBy('name', 'London');
     $this->assertInstanceOf(LazyRelationshipCollection::class, $london->getHabitants());
     $this->assertCount(2, $london->getHabitants());
     /** @var LivesIn $livesIn */
     foreach ($london->getHabitants() as $livesIn) {
         $this->assertInstanceOf(User::class, $livesIn->getUser());
         $this->assertInstanceOf(City::class, $livesIn->getCity());
         $this->assertEquals(123, $livesIn->getSince());
         $this->assertInstanceOf(LivesIn::class, $livesIn->getUser()->getLivesIn());
     }
     $u = $london->getHabitants()[0];
     $london->getHabitants()->removeElement($u);
     $u->getUser()->removeCity($u->getCity());
     $this->em->flush();
 }
 /**
  * @group flush-1
  * @group flush
  */
 public function testManagedEntityIsFlushedOnBooleanLabelUpdate()
 {
     $user = new User('ikwattro');
     $user->setActive();
     $this->em->persist($user);
     $this->em->flush();
     $this->assertGraphExist('(u:User:Active {login:"******"})');
     $user->setInactive();
     $this->assertFalse($user->isActive());
     $this->em->flush();
     $this->assertGraphNotExist('(u:User:Active {login:"******"})');
 }
 public function testPaginatedWithCustomOrder()
 {
     $this->clearDb();
     for ($i = 0; $i <= 100; ++$i) {
         $user = new User('Login ' . $i);
         $user->setAge($i);
         $this->em->persist($user);
     }
     $this->em->flush();
     /** @var User[] $users */
     $users = $this->em->getRepository(User::class)->paginated(0, 10, ['age', BaseRepository::ORDER_DESC]);
     $this->assertCount(10, $users);
     $i = 100;
     foreach ($users as $user) {
         $this->assertEquals($i, $user->getAge());
         --$i;
     }
 }
 private function init()
 {
     $company = new Company('Acme');
     for ($i = 0; $i < 10; ++$i) {
         $u = new User('DummyUser' . $i);
         $u->setCurrentCompany($company);
         $company->addEmployee($u);
     }
     foreach ($company->getEmployees() as $employee) {
         foreach ($company->getEmployees() as $employee2) {
             if ($employee->getLogin() !== $employee2->getLogin()) {
                 $employee2->addLoves($employee);
                 $employee->addLovedBy($employee2);
             }
         }
     }
     $this->em->persist($company);
     $this->em->flush();
 }
 public function testCascadeHydrationForSimpleRelationshipsOnEndNodes()
 {
     $this->clearDb();
     $user1 = new User('user1');
     $user2 = new User('user2');
     $company = new Company('Acme');
     $user2->setCurrentCompany($company);
     $company->addEmployee($user2);
     $user1->addLoves($user2);
     $this->em->persist($user1);
     $this->em->persist($user2);
     $this->em->flush();
     $this->em->clear();
     /** @var User $user */
     $user = $this->em->getRepository(User::class)->findOneBy('login', 'user1');
     $this->assertCount(1, $user->getLoves());
     $friend = $user->getLoves()[0];
     $comp = $friend->getCurrentCompany();
     $this->assertEquals('Acme', $comp->getName());
 }
 /**
  * @group order-re-prop-lazy
  */
 public function testOrderByRelationshipEntityPropertiesLazyLoaded()
 {
     $this->clearDb();
     $a = new User('ikwattro');
     $b = new User('jexp');
     $c = new User('luanne');
     $city = new City('London');
     $a->setCity($city, 456790);
     $b->setCity($city, 456789);
     $c->setCity($city, 456791);
     $this->em->persist($city);
     $this->em->flush();
     $this->em->clear();
     /** @var City $city */
     $city = $this->em->getRepository(City::class)->findOneBy('name', 'London');
     $this->assertCount(3, $city->getHabitants());
     $this->assertEquals(456789, $city->getHabitants()[2]->getSince());
     $this->assertEquals(456790, $city->getHabitants()[1]->getSince());
     $this->assertEquals(456791, $city->getHabitants()[0]->getSince());
 }
 /**
  * @group multiple-rels-same
  */
 public function testMultipleRelationshipTypesWithSameName()
 {
     $this->clearDb();
     $user1 = new User('user1');
     $user2 = new User('user2');
     $user3 = new User('user3');
     $user4 = new User('user4');
     $user5 = new User('user5');
     $user6 = new User('user6');
     $user1->addLoves($user2);
     $user1->addLoves($user3);
     $user6->addLovedBy($user4);
     $user6->addLovedBy($user5);
     $this->em->persist($user1);
     $this->em->persist($user6);
     $this->em->flush();
     $this->em->clear();
     $this->assertGraphExist('(u2:User {login:"******"})<-[:IN_LOVE_WITH]-(u1:User {login: "******"})-[:IN_LOVE_WITH]->(u3:User {login: "******"})');
     $this->assertGraphExist('(u4:User {login:"******"})-[:IN_LOVE_WITH]->(u6:User {login:"******"})<-[:IN_LOVE_WITH]-(u5:User {login:"******"})');
     /** @var BaseRepository $repository */
     $repository = $this->em->getRepository(User::class);
     /** @var User $user */
     $user = $repository->findOneBy('login', 'user1');
     $this->assertCount(2, $user->getLoves());
     foreach ($user->getLoves() as $loved) {
         $this->assertCount(1, $loved->getLovedBy());
         $this->assertEquals('user1', $loved->getLovedBy()[0]->getLogin());
     }
     //$this->em->clear();
     /** @var User $u6 */
     $u6 = $repository->findOneBy('login', 'user6');
     $this->assertCount(2, $u6->getLovedBy());
     foreach ($u6->getLovedBy() as $lover) {
         $this->assertTrue($lover->getLoves()->contains($u6));
     }
 }
Exemplo n.º 8
0
 /**
  * @group label
  */
 public function testExtraLabelsAreHydrated()
 {
     $user = new User('ikwattro');
     $user->setActive();
     $this->em->persist($user);
     $this->em->flush();
     $this->em->clear();
     /** @var User $ikwattro */
     $ikwattro = $this->em->getRepository(User::class)->findOneBy('login', 'ikwattro');
     $this->assertTrue($ikwattro->isActive());
 }
Exemplo n.º 9
0
 private function init()
 {
     // Setup initial graph
     $this->clearDb();
     $user = new User('ikwattro');
     $role = new SecurityRole('view_pages');
     foreach (['wood', 'stone', 'water', 'sun', 'coat'] as $res) {
         $resource = new ResourceModel($res);
         $this->em->persist($resource);
     }
     $user->addRole($role);
     $this->em->persist($user);
     $this->em->flush();
     $this->em->clear();
 }