protected function generateFixture()
 {
     $manager1 = new CompanyManager();
     $manager1->setName('Roman B.');
     $manager1->setTitle('Foo');
     $manager1->setDepartment('IT');
     $manager1->setSalary(100000);
     $manager2 = new CompanyManager();
     $manager2->setName('Benjamin E.');
     $manager2->setTitle('Foo');
     $manager2->setDepartment('HR');
     $manager2->setSalary(200000);
     $manager3 = new CompanyManager();
     $manager3->setName('Guilherme B.');
     $manager3->setTitle('Foo');
     $manager3->setDepartment('Complaint Department');
     $manager3->setSalary(400000);
     $manager4 = new CompanyManager();
     $manager4->setName('Jonathan W.');
     $manager4->setTitle('Foo');
     $manager4->setDepartment('Administration');
     $manager4->setSalary(800000);
     $this->_em->persist($manager1);
     $this->_em->persist($manager2);
     $this->_em->persist($manager3);
     $this->_em->persist($manager4);
     $this->_em->flush();
     $this->_em->clear();
 }
Ejemplo n.º 2
0
 private function loadCompanySingleTableInheritanceFixtureData()
 {
     $contract1 = new CompanyFlexUltraContract();
     $contract2 = new CompanyFlexUltraContract();
     $contract2->markCompleted();
     $contract3 = new CompanyFlexContract();
     $contract4 = new CompanyFlexContract();
     $contract4->markCompleted();
     $manager = new CompanyManager();
     $manager->setName('Alexander');
     $manager->setSalary(42);
     $manager->setDepartment('Doctrine');
     $manager->setTitle('Filterer');
     $manager2 = new CompanyManager();
     $manager2->setName('Benjamin');
     $manager2->setSalary(1337);
     $manager2->setDepartment('Doctrine');
     $manager2->setTitle('Maintainer');
     $contract1->addManager($manager);
     $contract2->addManager($manager);
     $contract3->addManager($manager);
     $contract4->addManager($manager);
     $contract1->addManager($manager2);
     $contract1->setSalesPerson($manager);
     $contract2->setSalesPerson($manager);
     $this->_em->persist($manager);
     $this->_em->persist($manager2);
     $this->_em->persist($contract1);
     $this->_em->persist($contract2);
     $this->_em->persist($contract3);
     $this->_em->persist($contract4);
     $this->_em->flush();
     $this->_em->clear();
     $this->managerId = $manager->getId();
     $this->managerId2 = $manager2->getId();
     $this->contractId1 = $contract1->getId();
     $this->contractId2 = $contract2->getId();
 }
Ejemplo n.º 3
0
 /**
  * @group DDC-728
  */
 public function testQueryForInheritedSingleValuedAssociation()
 {
     $manager = new CompanyManager();
     $manager->setName('gblanco');
     $manager->setSalary(1234);
     $manager->setTitle('Awesome!');
     $manager->setDepartment('IT');
     $person = new CompanyPerson();
     $person->setName('spouse');
     $manager->setSpouse($person);
     $this->_em->persist($manager);
     $this->_em->persist($person);
     $this->_em->flush();
     $this->_em->clear();
     $dql = "SELECT m FROM Doctrine\\Tests\\Models\\Company\\CompanyManager m WHERE m.spouse = ?1";
     $dqlManager = $this->_em->createQuery($dql)->setParameter(1, $person->getId())->getSingleResult();
     $this->assertEquals($manager->getId(), $dqlManager->getId());
     $this->assertEquals($person->getId(), $dqlManager->getSpouse()->getId());
 }
 public function generateFixture()
 {
     $car = new CompanyCar('Caramba');
     $manager1 = new CompanyManager();
     $manager1->setName('Roman B.');
     $manager1->setTitle('Foo');
     $manager1->setDepartment('IT');
     $manager1->setSalary(100000);
     $manager1->setCar($car);
     $person2 = new CompanyEmployee();
     $person2->setName('Benjamin E.');
     $person2->setDepartment('IT');
     $person2->setSalary(200000);
     $person3 = new CompanyEmployee();
     $person3->setName('Guilherme B.');
     $person3->setDepartment('IT2');
     $person3->setSalary(400000);
     $person4 = new CompanyEmployee();
     $person4->setName('Jonathan W.');
     $person4->setDepartment('IT2');
     $person4->setSalary(800000);
     $person2->setSpouse($person3);
     $manager1->addFriend($person4);
     $person2->addFriend($person3);
     $person2->addFriend($person4);
     $person3->addFriend($person4);
     $this->_em->persist($car);
     $this->_em->persist($manager1);
     $this->_em->persist($person2);
     $this->_em->persist($person3);
     $this->_em->persist($person4);
     $this->_em->flush();
     $this->_em->clear();
 }
 /**
  * @group DDC-1777
  */
 public function testExistsSubclass()
 {
     $manager = new CompanyManager();
     $manager->setName('gblanco');
     $manager->setSalary(1234);
     $manager->setTitle('Awesome!');
     $manager->setDepartment('IT');
     $this->assertFalse($this->_em->getUnitOfWork()->getEntityPersister(get_class($manager))->exists($manager));
     $this->_em->persist($manager);
     $this->_em->flush();
     $this->assertTrue($this->_em->getUnitOfWork()->getEntityPersister(get_class($manager))->exists($manager));
 }
 public function testSelfReferencingOneToOne()
 {
     $manager = new CompanyManager();
     $manager->setName('John Smith');
     $manager->setSalary(100000);
     $manager->setDepartment('IT');
     $manager->setTitle('CTO');
     $wife = new CompanyPerson();
     $wife->setName('Mary Smith');
     $wife->setSpouse($manager);
     $this->assertSame($manager, $wife->getSpouse());
     $this->assertSame($wife, $manager->getSpouse());
     $this->_em->persist($manager);
     $this->_em->persist($wife);
     $this->_em->flush();
     //var_dump($this->_em->getConnection()->fetchAll('select * from company_persons'));
     //var_dump($this->_em->getConnection()->fetchAll('select * from company_employees'));
     //var_dump($this->_em->getConnection()->fetchAll('select * from company_managers'));
     $this->_em->clear();
     $query = $this->_em->createQuery('select p, s from Doctrine\\Tests\\Models\\Company\\CompanyPerson p join p.spouse s where p.name=\'Mary Smith\'');
     $result = $query->getResult();
     $this->assertEquals(1, count($result));
     $this->assertTrue($result[0] instanceof CompanyPerson);
     $this->assertEquals('Mary Smith', $result[0]->getName());
     $this->assertTrue($result[0]->getSpouse() instanceof CompanyEmployee);
     $this->assertEquals('John Smith', $result[0]->getSpouse()->getName());
     $this->assertSame($result[0], $result[0]->getSpouse()->getSpouse());
 }
 /**
  * @group DDC-992
  */
 public function testGetSubClassManyToManyCollection()
 {
     $manager = new CompanyManager();
     $manager->setName('gblanco');
     $manager->setSalary(1234);
     $manager->setTitle('Awesome!');
     $manager->setDepartment('IT');
     $person = new CompanyPerson();
     $person->setName('friend');
     $manager->addFriend($person);
     $this->_em->persist($manager);
     $this->_em->persist($person);
     $this->_em->flush();
     $this->_em->clear();
     $manager = $this->_em->find('Doctrine\\Tests\\Models\\Company\\CompanyManager', $manager->getId());
     $this->assertEquals(1, count($manager->getFriends()));
 }
Ejemplo n.º 8
0
 public function populate()
 {
     $groups = array();
     for ($j = 0; $j < 3; $j++) {
         $group = new CmsGroup();
         $group->name = "group{$j}";
         $groups[] = $group;
         $this->_em->persist($group);
     }
     for ($i = 0; $i < 9; $i++) {
         $user = new CmsUser();
         $user->name = "Name{$i}";
         $user->username = "******";
         $user->status = "active";
         $user->email = new CmsEmail();
         $user->email->user = $user;
         $user->email->email = "email{$i}";
         for ($j = 0; $j < 3; $j++) {
             $user->addGroup($groups[$j]);
         }
         $this->_em->persist($user);
         for ($j = 0; $j < $i + 1; $j++) {
             $article = new CmsArticle();
             $article->topic = "topic{$i}{$j}";
             $article->text = "text{$i}{$j}";
             $article->setAuthor($user);
             $article->version = 0;
             $this->_em->persist($article);
         }
     }
     for ($i = 0; $i < 9; $i++) {
         $company = new Company();
         $company->name = "name{$i}";
         $company->logo = new Logo();
         $company->logo->image = "image{$i}";
         $company->logo->image_width = 100 + $i;
         $company->logo->image_height = 100 + $i;
         $company->logo->company = $company;
         for ($j = 0; $j < 3; $j++) {
             $department = new Department();
             $department->name = "name{$i}{$j}";
             $department->company = $company;
             $company->departments[] = $department;
         }
         $this->_em->persist($company);
     }
     for ($i = 0; $i < 9; $i++) {
         $user = new User1();
         $user->name = "name{$i}";
         $user->email = "email{$i}";
         $this->_em->persist($user);
     }
     $manager = new CompanyManager();
     $manager->setName('Roman B.');
     $manager->setTitle('Foo');
     $manager->setDepartment('IT');
     $manager->setSalary(100000);
     $this->_em->persist($manager);
     $this->_em->flush();
 }
 /**
  * @group DDC-1637
  */
 public function testMatching()
 {
     $manager = new CompanyManager();
     $manager->setName('gblanco');
     $manager->setSalary(1234);
     $manager->setTitle('Awesome!');
     $manager->setDepartment('IT');
     $this->_em->persist($manager);
     $this->_em->flush();
     $repository = $this->_em->getRepository("Doctrine\\Tests\\Models\\Company\\CompanyEmployee");
     $users = $repository->matching(new Criteria(Criteria::expr()->eq('department', 'IT')));
     $this->assertEquals(1, count($users));
     $repository = $this->_em->getRepository("Doctrine\\Tests\\Models\\Company\\CompanyManager");
     $users = $repository->matching(new Criteria(Criteria::expr()->eq('department', 'IT')));
     $this->assertEquals(1, count($users));
 }
 /**
  * @group DDC-834
  */
 public function testGetReferenceEntityWithSubclasses()
 {
     $manager = new CompanyManager();
     $manager->setName('gblanco');
     $manager->setSalary(1234);
     $manager->setTitle('Awesome!');
     $manager->setDepartment('IT');
     $this->_em->persist($manager);
     $this->_em->flush();
     $this->_em->clear();
     $ref = $this->_em->getReference('Doctrine\\Tests\\Models\\Company\\CompanyPerson', $manager->getId());
     $this->assertNotInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref, "Cannot Request a proxy from a class that has subclasses.");
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyPerson', $ref);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $ref, "Direct fetch of the reference has to load the child class Emplyoee directly.");
     $this->_em->clear();
     $ref = $this->_em->getReference('Doctrine\\Tests\\Models\\Company\\CompanyManager', $manager->getId());
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference.");
 }
 /**
  * @group DDC-817
  */
 public function testFindByAssociation()
 {
     $manager = new CompanyManager();
     $manager->setName('gblanco');
     $manager->setSalary(1234);
     $manager->setTitle('Awesome!');
     $manager->setDepartment('IT');
     $person = new CompanyPerson();
     $person->setName('spouse');
     $manager->setSpouse($person);
     $this->_em->persist($manager);
     $this->_em->persist($person);
     $this->_em->flush();
     $this->_em->clear();
     $repos = $this->_em->getRepository('Doctrine\\Tests\\Models\\Company\\CompanyManager');
     $pmanager = $repos->findOneBy(array('spouse' => $person->getId()));
     $this->assertEquals($manager->getId(), $pmanager->getId());
     $repos = $this->_em->getRepository('Doctrine\\Tests\\Models\\Company\\CompanyPerson');
     $pmanager = $repos->findOneBy(array('spouse' => $person->getId()));
     $this->assertEquals($manager->getId(), $pmanager->getId());
 }