Failed Conditions
Pull Request — master (#7796)
by
unknown
09:55
created

GH7761Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Annotation as ORM;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
11
final class GH7761Test extends OrmFunctionalTestCase
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    protected function setUp() : void
17
    {
18
        parent::setUp();
19
20
        $this->setUpEntitySchema([
21
            GH7761Entity::class,
22
            GH7761ChildEntity::class,
23
        ]);
24
25
        $parent = new GH7761Entity();
26
        $child  = new GH7761ChildEntity();
27
        $parent->children->add($child);
28
29
        $this->em->persist($parent);
30
        $this->em->persist($child);
31
        $this->em->flush();
32
        $this->em->clear();
33
    }
34
35
    public function testCollectionClearDoesNotClearIfNotPersisted() : void
36
    {
37
        /** @var GH7761Entity $entity */
38
        $entity = $this->em->find(GH7761Entity::class, 1);
39
        $entity->children->clear();
40
        $this->em->persist(new GH7761Entity());
41
        $this->em->flush();
42
43
        $this->em->clear();
44
45
        $entity = $this->em->find(GH7761Entity::class, 1);
46
        self::assertCount(1, $entity->children);
47
48
        $this->em->clear();
49
    }
50
}
51
52
/**
53
 * @ORM\Entity
54
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
55
 */
56
class GH7761Entity
57
{
58
    /**
59
     * @ORM\Id
60
     * @ORM\Column(type="integer")
61
     * @ORM\GeneratedValue
62
     */
63
    public $id;
64
65
    /**
66
     * @ORM\ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7761ChildEntity", cascade={"all"})
67
     * @ORM\JoinTable(name="gh7761_to_child",
68
     *     joinColumns={@ORM\JoinColumn(name="entity_id")},
69
     *     inverseJoinColumns={@ORM\JoinColumn(name="child_id")}
70
     * )
71
     */
72
    public $children;
73
74
    public function __construct()
75
    {
76
        $this->children = new ArrayCollection();
77
    }
78
}
79
80
/**
81
 * @ORM\Entity
82
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
83
 */
84
class GH7761ChildEntity
85
{
86
    /**
87
     * @ORM\Id
88
     * @ORM\Column(type="integer")
89
     * @ORM\GeneratedValue
90
     */
91
    public $id;
92
}
93