|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 4 | + |
| 5 | +use Doctrine\ORM\AbstractQuery; |
| 6 | +use Doctrine\ORM\Internal\Hydration\HydrationException; |
| 7 | + |
| 8 | +/** |
| 9 | + * @group DDC-2306 |
| 10 | + */ |
| 11 | +class DDC3170Test extends \Doctrine\Tests\OrmFunctionalTestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * {@inheritDoc} |
| 15 | + */ |
| 16 | + protected function setup() |
| 17 | + { |
| 18 | + parent::setup(); |
| 19 | + |
| 20 | + $this->_schemaTool->createSchema( |
| 21 | + array( |
| 22 | + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170AbstractEntityJoined'), |
| 23 | + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170ProductJoined'), |
| 24 | + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170AbstractEntitySingleTable'), |
| 25 | + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170ProductSingleTable'), |
| 26 | + ) |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Tests that the discriminator column is correctly read from the meta mappings when fetching a |
| 32 | + * child from an inheritance mapped class. |
| 33 | + * |
| 34 | + * The simple object hydration maps the type field to a field alias like type2. This mapping needs |
| 35 | + * to be considered when loading the discriminator column's value from the SQL result. |
| 36 | + * |
| 37 | + * {@see \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator::hydrateRowData()} |
| 38 | + */ |
| 39 | + public function testIssue() |
| 40 | + { |
| 41 | + // $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); |
| 42 | + |
| 43 | + $productJoined = new DDC3170ProductJoined(); |
| 44 | + $productSingleTable = new DDC3170ProductSingleTable(); |
| 45 | + $this->_em->persist($productJoined); |
| 46 | + $this->_em->persist($productSingleTable); |
| 47 | + $this->_em->flush(); |
| 48 | + $this->_em->clear(); |
| 49 | + |
| 50 | + try { |
| 51 | + $this->_em->createQueryBuilder() |
| 52 | + ->select('p') |
| 53 | + ->from(__NAMESPACE__ . '\\DDC3170ProductJoined', 'p') |
| 54 | + ->getQuery() |
| 55 | + ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); |
| 56 | + } catch (HydrationException $e) // Thrown by SimpleObjectHydrator |
| 57 | + { |
| 58 | + $this->fail('Failed correct mapping of discriminator column when using simple object hydration and class table inheritance'); |
| 59 | + } |
| 60 | + |
| 61 | + try { |
| 62 | + $this->_em->createQueryBuilder() |
| 63 | + ->select('p') |
| 64 | + ->from(__NAMESPACE__ . '\\DDC3170ProductSingleTable', 'p') |
| 65 | + ->getQuery() |
| 66 | + ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); |
| 67 | + } catch (HydrationException $e) // Thrown by SimpleObjectHydrator |
| 68 | + { |
| 69 | + $this->fail('Failed correct mapping of discriminator column when using simple object hydration and single table inheritance'); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +/** |
| 75 | + * @Entity |
| 76 | + * @InheritanceType("JOINED") |
| 77 | + * @DiscriminatorColumn(name="type", type="string") |
| 78 | + * @DiscriminatorMap({"product" = "DDC3170ProductJoined"}) |
| 79 | + */ |
| 80 | +abstract class DDC3170AbstractEntityJoined |
| 81 | +{ |
| 82 | + /** @Id @Column(type="integer") @GeneratedValue */ |
| 83 | + public $id; |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * @Entity |
| 88 | + */ |
| 89 | +class DDC3170ProductJoined extends DDC3170AbstractEntityJoined |
| 90 | +{ |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * @Entity |
| 95 | + * @InheritanceType("SINGLE_TABLE") |
| 96 | + * @DiscriminatorColumn(name="type", type="string") |
| 97 | + * @DiscriminatorMap({"product" = "DDC3170ProductSingleTable"}) |
| 98 | + */ |
| 99 | +abstract class DDC3170AbstractEntitySingleTable |
| 100 | +{ |
| 101 | + /** @Id @Column(type="integer") @GeneratedValue */ |
| 102 | + public $id; |
| 103 | +} |
| 104 | + |
| 105 | +/** |
| 106 | + * @Entity |
| 107 | + */ |
| 108 | +class DDC3170ProductSingleTable extends DDC3170AbstractEntitySingleTable |
| 109 | +{ |
| 110 | +} |
0 commit comments