public function testPartiallyUpdate()
 {
     $this->assertCount(0, $this->logrepo->findAll());
     $user = new User();
     $user->setName('firstName');
     $user->setCompany('firstCompany');
     $this->em->persist($user);
     $this->em->flush();
     $this->assertCount(1, $this->logrepo->findAll());
     $this->assertEquals(array('name'), $user->getFieldsToSchedule());
     $this->assertEquals('firstName', $user->getName());
     $this->assertEquals('firstCompany', $user->getCompany());
     $user->setName('firstName new');
     $user->setCompany('firstCompany new');
     $user->setScheduledChangeDate(new \DateTime("+ 100 days"));
     $this->em->persist($user);
     $this->em->flush();
     $logs = $this->logrepo->findAll();
     $this->assertCount(2, $logs);
     $this->assertEquals('firstName', $user->getName());
     $this->assertEquals('firstCompany new', $user->getCompany());
     $changes = $this->changeRepo->findAll();
     $this->assertCount(1, $changes);
     $change = array_pop($changes);
     $data = $change->getData();
     $dataold = $change->getOldData();
     $this->assertEquals($change->getObjectId(), $user->getId());
     $this->assertEquals($change->getObjectClass(), get_class($user));
     $this->assertArrayHasKey('name', $data);
     $this->assertEquals('firstName new', $data['name']);
     $this->assertArrayNotHasKey('company', $data);
     $this->assertArrayHasKey('name', $dataold);
     $this->assertEquals('firstName', $dataold['name']);
     $log = array_pop($logs);
     $data = $log->getData();
     $dataold = $log->getOldData();
     $this->assertEquals($log->getObjectId(), $user->getId());
     $this->assertEquals($log->getObjectClass(), get_class($user));
     $this->assertArrayHasKey('company', $data);
     $this->assertEquals('firstCompany new', $data['company']);
     $this->assertArrayNotHasKey('name', $data);
     $this->assertArrayHasKey('company', $dataold);
     $this->assertEquals('firstCompany', $dataold['company']);
 }
Ejemplo n.º 2
0
 public function testEditMany2Many()
 {
     $this->assertCount(0, $this->logrepo->findAll());
     $art0 = new Article();
     $art0->setTitle('Title');
     $art1 = new Article();
     $art1->setTitle('Title1');
     $art2 = new Article();
     $art2->setTitle('Title2');
     $user = new User();
     $user->setName('Username');
     $user1 = new User();
     $user1->setName('Username2');
     $user2 = new User();
     $user2->setName('Username3');
     $this->em->persist($user);
     $this->em->persist($user1);
     $this->em->persist($user2);
     $this->em->persist($art0);
     $this->em->persist($art1);
     $this->em->persist($art2);
     $this->em->flush();
     $logs = $this->mainlogrepo->findAll();
     $this->assertCount(6, $logs);
     $user->addArticle($art0);
     $user->addArticle($art1);
     $this->em->flush();
     $logs = $this->mainlogrepo->findAll();
     $this->assertCount(8, $logs);
     $logs = $this->mainlogrepo->getLogsByObject($user);
     $this->assertCount(3, $logs);
     $manylog = array_shift($logs);
     $this->assertInstanceOf(get_class(new LogMany2Many()), $manylog);
     $this->assertEquals($manylog->getInverseClass(), get_class($art1));
     $this->assertEquals($manylog->getInverseId(), $art1->getId());
     $this->assertEquals($manylog->getObjectClass(), get_class($user));
     $this->assertEquals($manylog->getObjectId(), $user->getId());
     $manylog = array_shift($logs);
     $this->assertInstanceOf(get_class(new LogMany2Many()), $manylog);
     $this->assertEquals($manylog->getInverseClass(), get_class($art0));
     $this->assertEquals($manylog->getInverseId(), $art0->getId());
     $this->assertEquals($manylog->getObjectClass(), get_class($user));
     $this->assertEquals($manylog->getObjectId(), $user->getId());
     $logs = $this->logrepoMany->getLogsByObject($art1);
     $this->assertCount(1, $logs);
     $manylog = array_pop($logs);
     $this->assertInstanceOf(get_class(new LogMany2Many()), $manylog, true, true);
     $this->assertEquals($manylog->getInverseClass(), get_class($art1));
     $this->assertEquals($manylog->getInverseId(), $art1->getId());
     $this->assertEquals($manylog->getObjectClass(), get_class($user));
     $this->assertEquals($manylog->getObjectId(), $user->getId());
     $logs = $this->logrepoMany->getLogsByObject($art0);
     $this->assertCount(1, $logs);
     $manylog = array_pop($logs);
     $this->assertInstanceOf(get_class(new LogMany2Many()), $manylog, true, true);
     $this->assertEquals($manylog->getInverseClass(), get_class($art0));
     $this->assertEquals($manylog->getInverseId(), $art0->getId());
     $this->assertEquals($manylog->getObjectClass(), get_class($user));
     $this->assertEquals($manylog->getObjectId(), $user->getId());
 }