Example #1
0
 /**
  * @group DDC-163
  */
 public function testQueryWithOrConditionUsingTwoRelationOnSameEntity()
 {
     $p1 = new CompanyPerson();
     $p1->setName('p1');
     $p2 = new CompanyPerson();
     $p2->setName('p2');
     $p3 = new CompanyPerson();
     $p3->setName('p3');
     $p4 = new CompanyPerson();
     $p4->setName('p4');
     $p1->setSpouse($p3);
     $p1->addFriend($p2);
     $p2->addFriend($p3);
     $p3->addFriend($p4);
     $this->_em->persist($p1);
     $this->_em->persist($p2);
     $this->_em->persist($p3);
     $this->_em->persist($p4);
     $this->_em->flush();
     $this->_em->clear();
     $dql = 'SELECT PARTIAL person.{id,name}, PARTIAL spouse.{id,name}, PARTIAL friend.{id,name}
         FROM  Doctrine\\Tests\\Models\\Company\\CompanyPerson person
         LEFT JOIN person.spouse spouse
         LEFT JOIN person.friends friend
         LEFT JOIN spouse.friends spouse_friend
         LEFT JOIN friend.friends friend_friend
         WHERE person.name=:name AND (spouse_friend.name=:name2 OR friend_friend.name=:name2)';
     $q = $this->_em->createQuery($dql);
     $q->setParameter('name', "p1");
     $q->setParameter('name2', "p4");
     $result = $q->getScalarResult();
     $this->assertEquals('p3', $result[0]['spouse_name']);
     $this->assertEquals('p1', $result[0]['person_name']);
     $this->assertEquals('p2', $result[0]['friend_name']);
 }
Example #2
0
 public function testQueryCache()
 {
     $person = new CompanyPerson();
     $person->setName('p1');
     $employee = new CompanyEmployee();
     $employee->setName('Foo');
     $employee->setDepartment('bar');
     $employee->setSalary(1000);
     $this->_em->persist($person);
     $this->_em->persist($employee);
     $this->_em->flush();
     $this->_em->clear();
     $dql = 'SELECT u FROM Doctrine\\Tests\\Models\\Company\\CompanyPerson u WHERE u INSTANCE OF :type';
     $class1 = $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\Company\\CompanyEmployee');
     $class2 = $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\Company\\CompanyPerson');
     $result1 = $this->_em->createQuery($dql)->setParameter('type', $class1)->useQueryCache(true)->getResult();
     $result2 = $this->_em->createQuery($dql)->setParameter('type', $class2)->useQueryCache(true)->getResult();
     $this->assertCount(1, $result1);
     $this->assertCount(1, $result2);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $result1[0]);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyPerson', $result2[0]);
     $this->assertNotInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $result2[0]);
 }
Example #3
0
 private function loadCompanyJoinedSubclassFixtureData()
 {
     $manager = new CompanyManager();
     $manager->setName('Roman');
     $manager->setTitle('testlead');
     $manager->setSalary(42);
     $manager->setDepartment('persisters');
     $manager2 = new CompanyManager();
     $manager2->setName('Guilherme');
     $manager2->setTitle('devlead');
     $manager2->setSalary(42);
     $manager2->setDepartment('parsers');
     $person = new CompanyPerson();
     $person->setName('Benjamin');
     $this->_em->persist($manager);
     $this->_em->persist($manager2);
     $this->_em->persist($person);
     $this->_em->flush();
     $this->_em->clear();
 }
 /**
  * @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());
 }
Example #5
0
 /**
  * @group DDC-1663
  */
 public function testNativeNamedQueryInheritance()
 {
     $person = new CompanyPerson();
     $person->setName('Fabio B. Silva');
     $employee = new CompanyEmployee();
     $employee->setName('Fabio Silva');
     $employee->setSalary(100000);
     $employee->setDepartment('IT');
     $this->_em->persist($person);
     $this->_em->persist($employee);
     $this->_em->flush();
     $this->_em->clear();
     $repository = $this->_em->getRepository('Doctrine\\Tests\\Models\\Company\\CompanyPerson');
     $result = $repository->createNativeNamedQuery('fetchAllWithSqlResultSetMapping')->getResult();
     $this->assertEquals(2, count($result));
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyPerson', $result[0]);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $result[1]);
     $this->assertTrue(is_numeric($result[0]->getId()));
     $this->assertTrue(is_numeric($result[1]->getId()));
     $this->assertEquals('Fabio B. Silva', $result[0]->getName());
     $this->assertEquals('Fabio Silva', $result[1]->getName());
     $this->_em->clear();
     $result = $repository->createNativeNamedQuery('fetchAllWithResultClass')->getResult();
     $this->assertEquals(2, count($result));
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyPerson', $result[0]);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $result[1]);
     $this->assertTrue(is_numeric($result[0]->getId()));
     $this->assertTrue(is_numeric($result[1]->getId()));
     $this->assertEquals('Fabio B. Silva', $result[0]->getName());
     $this->assertEquals('Fabio Silva', $result[1]->getName());
 }
 /**
  * @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()));
 }
 public function testSelfReferencingManyToMany()
 {
     $person1 = new CompanyPerson();
     $person1->setName('Roman');
     $person2 = new CompanyPerson();
     $person2->setName('Jonathan');
     $person1->addFriend($person2);
     $this->assertEquals(1, count($person1->getFriends()));
     $this->assertEquals(1, count($person2->getFriends()));
     $this->_em->persist($person1);
     $this->_em->persist($person2);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('select p, f from Doctrine\\Tests\\Models\\Company\\CompanyPerson p join p.friends f where p.name=?1');
     $query->setParameter(1, 'Roman');
     $result = $query->getResult();
     $this->assertEquals(1, count($result));
     $this->assertEquals(1, count($result[0]->getFriends()));
     $this->assertEquals('Roman', $result[0]->getName());
     $friends = $result[0]->getFriends();
     $this->assertEquals('Jonathan', $friends[0]->getName());
 }
 /**
  * @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());
 }
 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->save($manager);
     $this->_em->save($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->getResultList();
     $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);
     //var_dump($result);
 }