/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php

https://github.com/jaikdean/doctrine2 · PHP · 83 lines · 62 code · 18 blank · 3 comment · 0 complexity · ffa0ffa04fcaab56c1c6523956673086 MD5 · raw file

  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Tests\ORM\Functional\Ticket;
  4. use Doctrine\Tests\Models\Company\CompanyEmployee;
  5. use Doctrine\Tests\Models\Company\CompanyPerson;
  6. use Doctrine\Tests\OrmFunctionalTestCase;
  7. /**
  8. * @group DDC-1995
  9. */
  10. class DDC1995Test extends OrmFunctionalTestCase
  11. {
  12. public function setUp() : void
  13. {
  14. $this->useModelSet('company');
  15. parent::setUp();
  16. }
  17. public function testIssue() : void
  18. {
  19. $person = new CompanyPerson();
  20. $person->setName('p1');
  21. $employee = new CompanyEmployee();
  22. $employee->setName('Foo');
  23. $employee->setDepartment('bar');
  24. $employee->setSalary(1000);
  25. $this->em->persist($person);
  26. $this->em->persist($employee);
  27. $this->em->flush();
  28. $this->em->clear();
  29. $dql = 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1';
  30. $class = $this->em->getClassMetadata(CompanyEmployee::class);
  31. $result = $this->em->createQuery($dql)
  32. ->setParameter(1, $class)
  33. ->getResult();
  34. self::assertCount(1, $result);
  35. self::assertInstanceOf(CompanyEmployee::class, $result[0]);
  36. }
  37. public function testQueryCache() : void
  38. {
  39. $person = new CompanyPerson();
  40. $person->setName('p1');
  41. $employee = new CompanyEmployee();
  42. $employee->setName('Foo');
  43. $employee->setDepartment('bar');
  44. $employee->setSalary(1000);
  45. $this->em->persist($person);
  46. $this->em->persist($employee);
  47. $this->em->flush();
  48. $this->em->clear();
  49. $dql = 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF :type';
  50. $class1 = $this->em->getClassMetadata(CompanyEmployee::class);
  51. $class2 = $this->em->getClassMetadata(CompanyPerson::class);
  52. $result1 = $this->em->createQuery($dql)
  53. ->setParameter('type', $class1)
  54. ->useQueryCache(true)
  55. ->getResult();
  56. $result2 = $this->em->createQuery($dql)
  57. ->setParameter('type', $class2)
  58. ->useQueryCache(true)
  59. ->getResult();
  60. self::assertCount(1, $result1);
  61. self::assertCount(2, $result2);
  62. self::assertContainsOnlyInstancesOf(CompanyEmployee::class, $result1);
  63. self::assertContainsOnlyInstancesOf(CompanyPerson::class, $result2);
  64. }
  65. }