Failed Conditions
Pull Request — master (#6616)
by Marco
14:12
created

DDC6613InverseSide::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\PersistentCollection;
7
use Doctrine\Tests\OrmFunctionalTestCase;
8
9
/**
10
 * @group #6613
11
 * @group #6614
12
 */
13
class DDC6613Test extends OrmFunctionalTestCase
14
{
15
    public function setUp()
16
    {
17
        parent::setUp();
18
19
        $this->setUpEntitySchema([
20
            DDC6613InverseSide::class,
21
            DDC6613OwningSide::class,
22
        ]);
23
    }
24
25
    public function testFail()
26
    {
27
        $owningSide = new DDC6613OwningSide();
28
29
        $this->_em->persist($owningSide);
30
        $this->_em->flush();
31
        $this->_em->clear();
32
33
        $item1 = new DDC6613InverseSide();
34
        $item2 = new DDC6613InverseSide();
35
36
        $this->_em->persist($item1);
37
        $this->_em->persist($item2);
38
        $this->_em->flush();
39
40
        /* @var DDC6613OwningSide $foundOwningSide */
41
        $foundOwningSide = $this->_em->find(DDC6613OwningSide::class, $owningSide->id);
42
43
        self::assertInstanceOf(DDC6613OwningSide::class, $foundOwningSide);
44
45
        /* @var $phones PersistentCollection */
46
        $phones = $foundOwningSide->phones;
47
48
        self::assertInstanceOf(PersistentCollection::class, $phones);
49
        self::assertFalse($phones->isInitialized());
50
        self::assertFalse($phones->isDirty());
51
52
        $phones->add($item1);
53
54
        self::assertFalse($phones->isInitialized());
55
        self::assertTrue($phones->isDirty());
56
57
        $this->_em->flush();
58
59
        self::assertFalse($phones->isInitialized());
60
        self::assertFalse($phones->isDirty());
61
62
        $phones->add($item2);
63
64
        self::assertFalse($phones->isInitialized());
65
        self::assertTrue($phones->isDirty());
66
67
        $phones->initialize();
68
69
        self::assertTrue($phones->isInitialized());
70
        self::assertTrue($phones->isDirty());
71
        self::assertCount(2, $phones);
72
73
        $this->_em->flush();
74
75
        self::assertFalse($phones->isDirty());
76
        self::assertTrue($phones->isInitialized());
77
        self::assertCount(2, $foundOwningSide->phones);
78
    }
79
}
80
81
/** @Entity */
82
class DDC6613OwningSide
83
{
84
    /** @Id @Column(type="string") */
85
    public $id;
86
87
    /** @ManyToMany(targetEntity=DDC6613InverseSide::class) */
88
    public $phones;
89
90
    public function __construct()
91
    {
92
        $this->id     = uniqid('user', true);
93
        $this->phones = new ArrayCollection();
94
    }
95
}
96
97
/** @Entity */
98
class DDC6613InverseSide
99
{
100
    /** @Id @Column(type="string") */
101
    private $id;
102
103
    public function __construct()
104
    {
105
        $this->id = uniqid('phone', true);
106
    }
107
}