addLoves() public method

public addLoves ( User $user )
$user User
コード例 #1
0
 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());
 }
コード例 #2
0
 /**
  * @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));
     }
 }