File: GH11500Test.php

package info (click to toggle)
doctrine 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 11,236 kB
  • sloc: php: 105,633; xml: 1,312; makefile: 35; sh: 14
file content (109 lines) | stat: -rw-r--r-- 3,520 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH11500Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEntitySchema([
            GH11500AbstractTestEntity::class,
            GH11500TestEntityOne::class,
            GH11500TestEntityTwo::class,
            GH11500TestEntityHolder::class,
        ]);
    }

    /** @throws ORMException */
    public function testDeleteOneToManyCollectionWithSingleTableInheritance(): void
    {
        $testEntityOne    = new GH11500TestEntityOne();
        $testEntityTwo    = new GH11500TestEntityTwo();
        $testEntityHolder = new GH11500TestEntityHolder();

        $testEntityOne->testEntityHolder = $testEntityHolder;
        $testEntityHolder->testEntityOnes->add($testEntityOne);

        $testEntityTwo->testEntityHolder = $testEntityHolder;
        $testEntityHolder->testEntityTwos->add($testEntityTwo);

        $em = $this->getEntityManager();
        $em->persist($testEntityOne);
        $em->persist($testEntityTwo);
        $em->persist($testEntityHolder);
        $em->flush();

        $testEntityTwosBeforeRemovalOfTestEntityOnes = $testEntityHolder->testEntityTwos->toArray();

        $testEntityHolder->testEntityOnes = new ArrayCollection();
        $em->persist($testEntityHolder);
        $em->flush();
        $em->refresh($testEntityHolder);

        static::assertEmpty($testEntityHolder->testEntityOnes->toArray(), 'All records should have been deleted');
        static::assertEquals($testEntityTwosBeforeRemovalOfTestEntityOnes, $testEntityHolder->testEntityTwos->toArray(), 'Different Entity\'s records should not have been deleted');
    }
}



#[ORM\Entity]
#[ORM\Table(name: 'one_to_many_single_table_inheritance_test_entities')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap(['test_entity_one' => 'GH11500TestEntityOne', 'test_entity_two' => 'GH11500TestEntityTwo'])]
class GH11500AbstractTestEntity
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    public int|null $id = null;
}


#[ORM\Entity]
class GH11500TestEntityOne extends GH11500AbstractTestEntity
{
    #[ORM\ManyToOne(inversedBy:'testEntityOnes')]
    #[ORM\JoinColumn(name:'test_entity_holder_id', referencedColumnName:'id')]
    public GH11500TestEntityHolder|null $testEntityHolder = null;
}

#[ORM\Entity]
class GH11500TestEntityTwo extends GH11500AbstractTestEntity
{
    #[ORM\ManyToOne(inversedBy:'testEntityTwos')]
    #[ORM\JoinColumn(name:'test_entity_holder_id', referencedColumnName:'id')]
    public GH11500TestEntityHolder|null $testEntityHolder = null;
}

#[ORM\Entity]
class GH11500TestEntityHolder
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    public int|null $id = null;

    #[ORM\OneToMany(targetEntity: 'GH11500TestEntityOne', mappedBy: 'testEntityHolder', orphanRemoval: true)]
    public Collection $testEntityOnes;

    #[ORM\OneToMany(targetEntity: 'GH11500TestEntityTwo', mappedBy: 'testEntityHolder', orphanRemoval: true)]
    public Collection $testEntityTwos;

    public function __construct()
    {
        $this->testEntityOnes = new ArrayCollection();
        $this->testEntityTwos = new ArrayCollection();
    }
}