Failed Conditions
Push — master ( 77e3e5...46b695 )
by Michael
26s queued 19s
created

Tests/ORM/Functional/Ticket/DDC1595Test.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\DBAL\Logging\DebugStack;
8
use Doctrine\ORM\Annotation as ORM;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
use function count;
11
12
/**
13
 * @group DDC-1595
14
 * @group DDC-1596
15
 * @group non-cacheable
16
 */
17
class DDC1595Test extends OrmFunctionalTestCase
18
{
19
    public function setUp() : void
20
    {
21
        parent::setUp();
22
23
        $this->em->getConnection()->getConfiguration()->setSQLLogger(new DebugStack());
24
25
        $this->schemaTool->createSchema(
26
            [
27
            $this->em->getClassMetadata(DDC1595BaseInheritance::class),
28
            $this->em->getClassMetadata(DDC1595InheritedEntity1::class),
29
            $this->em->getClassMetadata(DDC1595InheritedEntity2::class),
30
            ]
31
        );
32
    }
33
34
    public function testIssue() : void
35
    {
36
        $e1 = new DDC1595InheritedEntity1();
37
38
        $this->em->persist($e1);
39
        $this->em->flush();
40
        $this->em->clear();
41
42
        $sqlLogger  = $this->em->getConnection()->getConfiguration()->getSQLLogger();
43
        $repository = $this->em->getRepository(DDC1595InheritedEntity1::class);
44
45
        $entity1 = $repository->find($e1->id);
46
47
        // DDC-1596
48
        self::assertSQLEquals(
49
            'SELECT t0."id" AS c1, t0."type" FROM "base" t0 WHERE t0."id" = ? AND t0."type" IN (\'Entity1\')',
50
            $sqlLogger->queries[count($sqlLogger->queries)]['sql']
0 ignored issues
show
The property queries does not seem to exist on Doctrine\DBAL\Logging\NullLogger.
Loading history...
51
        );
52
53
        $entities = $entity1->getEntities()->getValues();
54
55
        self::assertSQLEquals(
56
            'SELECT t0."id" AS c1, t0."type" FROM "base" t0 INNER JOIN "entity1_entity2" ON t0."id" = "entity1_entity2"."item" WHERE "entity1_entity2"."parent" = ? AND t0."type" IN (\'Entity2\')',
57
            $sqlLogger->queries[count($sqlLogger->queries)]['sql']
58
        );
59
60
        $this->em->clear();
61
62
        $entity1 = $repository->find($e1->id);
63
64
        $entity1->getEntities()->count();
65
66
        self::assertSQLEquals(
67
            'SELECT COUNT(*) FROM "entity1_entity2" t WHERE t."parent" = ?',
68
            $sqlLogger->queries[count($sqlLogger->queries)]['sql']
69
        );
70
    }
71
}
72
73
/**
74
 * @ORM\Entity
75
 * @ORM\Table(name="base")
76
 *
77
 * @ORM\InheritanceType("SINGLE_TABLE")
78
 * @ORM\DiscriminatorColumn(name="type", type="string")
79
 * @ORM\DiscriminatorMap({
80
 *     "Entity1" = DDC1595InheritedEntity1::class,
81
 *     "Entity2" = DDC1595InheritedEntity2::class
82
 * })
83
 */
84
abstract class DDC1595BaseInheritance
85
{
86
    /**
87
     * @ORM\Id @ORM\GeneratedValue
88
     * @ORM\Column(type="integer")
89
     *
90
     * @var int
91
     */
92
    public $id;
93
}
94
95
/**
96
 * @ORM\Entity
97
 */
98
class DDC1595InheritedEntity1 extends DDC1595BaseInheritance
99
{
100
    /**
101
     * @ORM\ManyToMany(targetEntity=DDC1595InheritedEntity2::class, fetch="EXTRA_LAZY")
102
     * @ORM\JoinTable(name="entity1_entity2",
103
     *     joinColumns={@ORM\JoinColumn(name="parent", referencedColumnName="id")},
104
     *     inverseJoinColumns={@ORM\JoinColumn(name="item", referencedColumnName="id")}
105
     * )
106
     */
107
    protected $entities;
108
109
    public function getEntities()
110
    {
111
        return $this->entities;
112
    }
113
}
114
115
/**
116
 * @ORM\Entity
117
 */
118
class DDC1595InheritedEntity2 extends DDC1595BaseInheritance
119
{
120
}
121