Passed
Pull Request — 2.6 (#7761)
by
unknown
08:33
created

testCollectionClearDoesNotClearIfNotPersisted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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