public function testCRUD()
 {
     $person = new CompanyPerson();
     $person->setName('Roman S. Borschel');
     $this->_em->save($person);
     $employee = new CompanyEmployee();
     $employee->setName('Roman S. Borschel');
     $employee->setSalary(100000);
     $employee->setDepartment('IT');
     $this->_em->save($employee);
     $employee->setName('Guilherme Blanco');
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery("select p from Doctrine\\Tests\\Models\\Company\\CompanyPerson p order by p.id asc");
     $entities = $query->getResultList();
     $this->assertEquals(2, count($entities));
     $this->assertTrue($entities[0] instanceof CompanyPerson);
     $this->assertTrue($entities[1] instanceof CompanyEmployee);
     $this->assertTrue(is_numeric($entities[0]->getId()));
     $this->assertTrue(is_numeric($entities[1]->getId()));
     $this->assertEquals('Roman S. Borschel', $entities[0]->getName());
     $this->assertEquals('Guilherme Blanco', $entities[1]->getName());
     $this->assertEquals(100000, $entities[1]->getSalary());
     $this->_em->clear();
     $query = $this->_em->createQuery("select p from Doctrine\\Tests\\Models\\Company\\CompanyEmployee p");
     $entities = $query->getResultList();
     $this->assertEquals(1, count($entities));
     $this->assertTrue($entities[0] instanceof CompanyEmployee);
     $this->assertTrue(is_numeric($entities[0]->getId()));
     $this->assertEquals('Guilherme Blanco', $entities[0]->getName());
     $this->assertEquals(100000, $entities[0]->getSalary());
     $this->_em->clear();
     /*
     $query = $this->_em->createQuery("select r,o from Doctrine\Tests\ORM\Functional\RelatedEntity r join r.owner o");
     
     $entities = $query->getResultList();
     $this->assertEquals(1, count($entities));
     $this->assertTrue($entities[0] instanceof RelatedEntity);
     $this->assertTrue(is_numeric($entities[0]->getId()));
     $this->assertEquals('theRelatedOne', $entities[0]->getName());
     $this->assertTrue($entities[0]->getOwner() instanceof ChildEntity);
     $this->assertEquals('thedata', $entities[0]->getOwner()->getData());
     $this->assertSame($entities[0], $entities[0]->getOwner()->getRelatedEntity());
     
     $query = $this->_em->createQuery("update Doctrine\Tests\ORM\Functional\ChildEntity e set e.data = 'newdata'");
     
     $affected = $query->execute();
     $this->assertEquals(1, $affected);
     
     $query = $this->_em->createQuery("delete Doctrine\Tests\ORM\Functional\ParentEntity e");
     
     $affected = $query->execute();
     $this->assertEquals(2, $affected);
     */
 }
 public function testSelectFieldOnRootEntity()
 {
     $employee = new CompanyEmployee();
     $employee->setName('Roman S. Borschel');
     $employee->setSalary(100000);
     $employee->setDepartment('IT');
     $this->_em->persist($employee);
     $this->_em->flush();
     $this->_em->clear();
     $q = $this->_em->createQuery('SELECT e.name FROM Doctrine\\Tests\\Models\\Company\\CompanyEmployee e');
     $this->assertEquals('SELECT c0_.name AS name0 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ ON c1_.id = c2_.id', $q->getSql());
 }
 public function testCRUD()
 {
     $person = new CompanyPerson();
     $person->setName('Roman S. Borschel');
     $this->_em->persist($person);
     $employee = new CompanyEmployee();
     $employee->setName('Roman S. Borschel');
     $employee->setSalary(100000);
     $employee->setDepartment('IT');
     $this->_em->persist($employee);
     $employee->setName('Guilherme Blanco');
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery("select p from Doctrine\\Tests\\Models\\Company\\CompanyPerson p order by p.name desc");
     $entities = $query->getResult();
     $this->assertEquals(2, count($entities));
     $this->assertTrue($entities[0] instanceof CompanyPerson);
     $this->assertTrue($entities[1] instanceof CompanyEmployee);
     $this->assertTrue(is_numeric($entities[0]->getId()));
     $this->assertTrue(is_numeric($entities[1]->getId()));
     $this->assertEquals('Roman S. Borschel', $entities[0]->getName());
     $this->assertEquals('Guilherme Blanco', $entities[1]->getName());
     $this->assertEquals(100000, $entities[1]->getSalary());
     $this->_em->clear();
     $query = $this->_em->createQuery("select p from Doctrine\\Tests\\Models\\Company\\CompanyEmployee p");
     $entities = $query->getResult();
     $this->assertEquals(1, count($entities));
     $this->assertTrue($entities[0] instanceof CompanyEmployee);
     $this->assertTrue(is_numeric($entities[0]->getId()));
     $this->assertEquals('Guilherme Blanco', $entities[0]->getName());
     $this->assertEquals(100000, $entities[0]->getSalary());
     $this->_em->clear();
     $guilherme = $this->_em->getRepository(get_class($employee))->findOneBy(array('name' => 'Guilherme Blanco'));
     $this->assertTrue($guilherme instanceof CompanyEmployee);
     $this->assertEquals('Guilherme Blanco', $guilherme->getName());
     $this->_em->clear();
     $query = $this->_em->createQuery("update Doctrine\\Tests\\Models\\Company\\CompanyEmployee p set p.name = ?1, p.department = ?2 where p.name='Guilherme Blanco' and p.salary = ?3");
     $query->setParameter(1, 'NewName', 'string');
     $query->setParameter(2, 'NewDepartment');
     $query->setParameter(3, 100000);
     $query->getSql();
     $numUpdated = $query->execute();
     $this->assertEquals(1, $numUpdated);
     $query = $this->_em->createQuery("delete from Doctrine\\Tests\\Models\\Company\\CompanyPerson p");
     $numDeleted = $query->execute();
     $this->assertEquals(2, $numDeleted);
 }
Пример #4
0
 /**
  * @group DDC-168
  */
 public function testJoinedSubclassPersisterRequiresSpecificOrderOfMetadataReflFieldsArray()
 {
     //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
     $spouse = new CompanyEmployee();
     $spouse->setName("Blub");
     $spouse->setDepartment("Accounting");
     $spouse->setSalary(500);
     $employee = new CompanyEmployee();
     $employee->setName("Foo");
     $employee->setDepartment("bar");
     $employee->setSalary(1000);
     $employee->setSpouse($spouse);
     $this->_em->persist($spouse);
     $this->_em->persist($employee);
     $this->_em->flush();
     $this->_em->clear();
     $q = $this->_em->createQuery("SELECT e FROM Doctrine\\Tests\\Models\\Company\\CompanyEmployee e WHERE e.name = ?1");
     $q->setParameter(1, "Foo");
     $theEmployee = $q->getSingleResult();
     $this->assertEquals("bar", $theEmployee->getDepartment());
     $this->assertEquals("Foo", $theEmployee->getName());
     $this->assertEquals(1000, $theEmployee->getSalary());
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $theEmployee);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', $theEmployee->getSpouse());
 }
Пример #5
0
 public function testIssue()
 {
     $className = 'Doctrine\\Tests\\Models\\Company\\CompanyEmployee';
     $date1 = new \DateTime('2011-11-11 11:11:11');
     $date2 = new \DateTime('2012-12-12 12:12:12');
     $employee1 = new CompanyEmployee();
     $employee2 = new CompanyEmployee();
     $employee1->setName("Fabio B. Silva");
     $employee1->setStartDate(new \DateTime('yesterday'));
     $employee1->setDepartment("R&D");
     $employee1->setSalary(100);
     $employee2->setName("Doctrine Bot");
     $employee1->setStartDate(new \DateTime('yesterday'));
     $employee2->setDepartment("QA");
     $employee2->setSalary(100);
     $this->_em->persist($employee1);
     $this->_em->persist($employee2);
     $this->_em->flush();
     $this->_em->clear();
     $this->_em->createQueryBuilder()->update($className, 'e')->set('e.startDate', ':date')->set('e.salary', ':salary')->where('e = :e')->setParameters(array('e' => $employee1, 'date' => $date1, 'salary' => 101))->getQuery()->useQueryCache(true)->execute();
     $this->_em->createQueryBuilder()->update($className, 'e')->set('e.startDate', ':date')->set('e.salary', ':salary')->where('e = :e')->setParameters(array('e' => $employee2, 'date' => $date2, 'salary' => 102))->getQuery()->useQueryCache(true)->execute();
     $this->_em->clear();
     $e1 = $this->_em->find($className, $employee1->getId());
     $e2 = $this->_em->find($className, $employee2->getId());
     $this->assertEquals(101, $e1->getSalary());
     $this->assertEquals(102, $e2->getSalary());
     $this->assertEquals($date1, $e1->getStartDate());
     $this->assertEquals($date2, $e2->getStartDate());
     $this->_em->createQueryBuilder()->update($className, 'e')->set('e.startDate', '?1')->set('e.salary', '?2')->where('e = ?0')->setParameters(array($employee1, $date1, 101))->getQuery()->useQueryCache(true)->execute();
     $this->_em->createQueryBuilder()->update($className, 'e')->set('e.startDate', '?1')->set('e.salary', '?2')->where('e = ?0')->setParameters(array($employee2, $date2, 102))->getQuery()->useQueryCache(true)->execute();
     $this->_em->clear();
     $e1 = $this->_em->find($className, $employee1->getId());
     $e2 = $this->_em->find($className, $employee2->getId());
     $this->assertEquals(101, $e1->getSalary());
     $this->assertEquals(102, $e2->getSalary());
     $this->assertEquals($date1, $e1->getStartDate());
     $this->assertEquals($date2, $e2->getStartDate());
 }
Пример #6
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]);
 }
Пример #7
0
 /**
  * @group DDC-130
  */
 public function testDeleteJoinTableRecords()
 {
     #$this->markTestSkipped('Nightmare! friends adds both ID 6-7 and 7-6 into two rows of the join table. How to detect this?');
     $employee1 = new CompanyEmployee();
     $employee1->setName('gblanco');
     $employee1->setSalary(0);
     $employee1->setDepartment('IT');
     $employee2 = new CompanyEmployee();
     $employee2->setName('jwage');
     $employee2->setSalary(0);
     $employee2->setDepartment('IT');
     $employee1->addFriend($employee2);
     $this->_em->persist($employee1);
     $this->_em->persist($employee2);
     $this->_em->flush();
     $employee1Id = $employee1->getId();
     $this->_em->remove($employee1);
     $this->_em->flush();
     $this->assertNull($this->_em->find(get_class($employee1), $employee1Id));
 }
Пример #8
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());
 }
 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();
 }