Beispiel #1
0
 public function testOneEmbedded()
 {
     $address = new Address();
     $address->setAddress('6512 Mercomatic Ct.');
     $address->setCity('Nashville');
     $address->setState('TN');
     $address->setZipcode('37209');
     $addressClone = clone $address;
     $user = new User();
     $user->setUsername('jwage');
     $this->dm->persist($user);
     $this->dm->flush();
     $user->setAddress($address);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId())->getQuery()->getSingleResult();
     $this->assertNotNull($user);
     $this->assertEquals($addressClone, $user->getAddress());
     $oldAddress = $user->getAddress();
     $address = new Address();
     $address->setAddress('Someplace else');
     $user->setAddress($address);
     $this->uow->computeChangeSets();
     $changeSet = $this->uow->getDocumentChangeSet($user);
     $this->assertNotEmpty($changeSet['address']);
     $this->assertSame($oldAddress, $changeSet['address'][0]);
     $this->assertSame($user->getAddress(), $changeSet['address'][1]);
 }
 public function testFindByEmbedOne()
 {
     $user = new User();
     $address = new Address();
     $address->setCity('Cracow');
     $user->setAddress($address);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->assertSame($user, $this->dm->getRepository(User::class)->findOneBy(['address' => $address]));
 }
 public function testOneEmbeddedReference()
 {
     $address = new Address();
     $address->setAddress('6512 Mercomatic Ct.');
     $address->setCity('Nashville');
     $address->setState('TN');
     $address->setZipcode('37209');
     $user = new User();
     $user->setUsername('jwage');
     $this->dm->persist($user);
     $this->dm->flush();
     $user->setAddress($address);
     $this->dm->flush();
     $this->dm->clear();
     $user2 = $this->dm->createQuery('Documents\\User')->where('id', $user->getId())->getSingleResult();
     $this->assertEquals($user->getAddress(), $user2->getAddress());
 }
Beispiel #4
0
 public function testOneEmbedded()
 {
     $address = new Address();
     $address->setAddress('6512 Mercomatic Ct.');
     $address->setCity('Nashville');
     $address->setState('TN');
     $address->setZipcode('37209');
     $addressClone = clone $address;
     $user = new User();
     $user->setUsername('jwage');
     $this->dm->persist($user);
     $this->dm->flush();
     $user->setAddress($address);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId())->getQuery()->getSingleResult();
     $this->assertNotNull($user);
     $this->assertEquals($addressClone, $user->getAddress());
 }
 public function testTest()
 {
     $employee = new Employee();
     $employee->setName('Employee');
     $employee->setSalary(50000.0);
     $employee->setStarted(new \DateTime());
     $address = new Address();
     $address->setAddress('555 Doctrine Rd.');
     $address->setCity('Nashville');
     $address->setState('TN');
     $address->setZipcode('37209');
     $employee->setAddress($address);
     $project = new Project('New Project');
     $manager = new Manager();
     $manager->setName('Manager');
     $manager->setSalary(100000.0);
     $manager->setStarted(new \DateTime());
     $manager->addProject($project);
     $this->dm->persist($employee);
     $this->dm->persist($address);
     $this->dm->persist($project);
     $this->dm->persist($manager);
     $this->dm->flush();
     $newProject = new Project('Another Project');
     $manager->setSalary(200000.0);
     $manager->addNote('Gave user 100k a year raise');
     $manager->incrementChanges(2);
     $manager->addProject($newProject);
     $this->dm->persist($newProject);
     $this->dm->flush();
     $this->dm->clear();
     $results = $this->dm->find('Documents\\Manager', array('name' => 'Manager'))->hydrate(false)->getResults();
     $result = current($results);
     $this->assertEquals(1, count($results));
     $this->assertEquals(200000.0, $result['salary']);
     $this->assertEquals(2, count($result['projects']));
     $this->assertEquals(1, count($result['notes']));
     $this->assertEquals('Gave user 100k a year raise', $result['notes'][0]);
 }
Beispiel #6
0
 public function testFavoritesReference()
 {
     $project = new Project('Test Project');
     $this->dm->persist($project);
     $this->dm->flush();
     $group = new Group('Test Group');
     $this->dm->persist($group);
     $this->dm->flush();
     $user = new FavoritesUser();
     $user->setName('favorites');
     $user->addFavorite($project);
     $user->addFavorite($group);
     $address = new Address();
     $address->setAddress('6512 Mercomatic Ct.');
     $address->setCity('Nashville');
     $address->setState('TN');
     $address->setZipcode('37209');
     $user->embed($address);
     $user->setEmbed($address);
     $document = new Phonenumber('6155139185');
     $user->embed($document);
     $user->setFavorite($project);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $test = $this->dm->getDocumentCollection('Documents\\Functional\\FavoritesUser')->findOne(array('name' => 'favorites'));
     $this->assertTrue(isset($test['favorites'][0]['type']));
     $this->assertEquals('project', $test['favorites'][0]['type']);
     $this->assertEquals('group', $test['favorites'][1]['type']);
     $this->assertTrue(isset($test['favorite']['_doctrine_class_name']));
     $this->assertEquals('Documents\\Project', $test['favorite']['_doctrine_class_name']);
     $user = $this->dm->getRepository('Documents\\Functional\\FavoritesUser')->findOneBy(array('name' => 'favorites'));
     $favorites = $user->getFavorites();
     $this->assertInstanceOf('Documents\\Project', $favorites[0]);
     $this->assertInstanceOf('Documents\\Group', $favorites[1]);
     $embedded = $user->getEmbedded();
     $this->assertInstanceOf('Documents\\Address', $embedded[0]);
     $this->assertInstanceOf('Documents\\Phonenumber', $embedded[1]);
     $this->assertInstanceOf('Documents\\Address', $user->getEmbed());
     $this->assertInstanceOf('Documents\\Project', $user->getFavorite());
 }