DDC168Test.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Tests\Models\Company\CompanyEmployee;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. class DDC168Test extends \Doctrine\Tests\OrmFunctionalTestCase
  6. {
  7. protected $oldMetadata;
  8. protected function setUp() {
  9. $this->useModelSet('company');
  10. parent::setUp();
  11. $this->oldMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee');
  12. $metadata = clone $this->oldMetadata;
  13. ksort($metadata->reflFields);
  14. $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $metadata);
  15. }
  16. public function tearDown()
  17. {
  18. $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $this->oldMetadata);
  19. parent::tearDown();
  20. }
  21. /**
  22. * @group DDC-168
  23. */
  24. public function testJoinedSubclassPersisterRequiresSpecificOrderOfMetadataReflFieldsArray()
  25. {
  26. //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
  27. $spouse = new CompanyEmployee;
  28. $spouse->setName("Blub");
  29. $spouse->setDepartment("Accounting");
  30. $spouse->setSalary(500);
  31. $employee = new CompanyEmployee;
  32. $employee->setName("Foo");
  33. $employee->setDepartment("bar");
  34. $employee->setSalary(1000);
  35. $employee->setSpouse($spouse);
  36. $this->_em->persist($spouse);
  37. $this->_em->persist($employee);
  38. $this->_em->flush();
  39. $this->_em->clear();
  40. $q = $this->_em->createQuery("SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e WHERE e.name = ?1");
  41. $q->setParameter(1, "Foo");
  42. $theEmployee = $q->getSingleResult();
  43. $this->assertEquals("bar", $theEmployee->getDepartment());
  44. $this->assertEquals("Foo", $theEmployee->getName());
  45. $this->assertEquals(1000, $theEmployee->getSalary());
  46. $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee);
  47. $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee->getSpouse());
  48. }
  49. }