Completed
Push — 2.6 ( 7e26d8...48bfef )
by Luís
11:42 queued 05:19
created

GH7761Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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
 * @Entity
53
 * @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
54
 */
55
class GH7761Entity
56
{
57
    /**
58
     * @Id
59
     * @Column(type="integer")
60
     * @GeneratedValue
61
     */
62
    public $id;
63
64
    /**
65
     * @ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7761ChildEntity", cascade={"all"})
66
     * @JoinTable(name="gh7761_to_child",
67
     *     joinColumns={@JoinColumn(name="entity_id")},
68
     *     inverseJoinColumns={@JoinColumn(name="child_id")}
69
     * )
70
     */
71
    public $children;
72
73
    public function __construct()
74
    {
75
        $this->children = new ArrayCollection();
76
    }
77
}
78
79
/**
80
 * @Entity
81
 * @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
82
 */
83
class GH7761ChildEntity
84
{
85
    /**
86
     * @Id
87
     * @Column(type="integer")
88
     * @GeneratedValue
89
     */
90
    public $id;
91
}
92