Failed Conditions
Pull Request — 2.6 (#7506)
by
unknown
09:52
created

DDC729Test::setUp()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 3
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 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\VerifyDeprecations;
8
9
class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase
10
{
11
    use VerifyDeprecations;
12
13
    public function setUp()
14
    {
15
        parent::setUp();
16
17
        try {
18
            $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
19
            $schemaTool->createSchema(
20
                [
21
                $this->_em->getClassMetadata(DDC729A::class),
22
                $this->_em->getClassMetadata(DDC729B::class),
23
                ]
24
            );
25
        } catch(\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
26
27
        }
28
    }
29
30
    /** @after */
31
    public function ensureTestGeneratedDeprecationMessages() : void
32
    {
33
        $this->assertHasDeprecationMessages();
34
    }
35
36
    public function testMergeManyToMany()
37
    {
38
        $a = new DDC729A();
39
        $b = new DDC729B();
40
        $a->related[] = $b;
41
42
        $this->_em->persist($a);
43
        $this->_em->persist($b);
44
        $this->_em->flush();
45
        $this->_em->clear();
46
        $aId = $a->id;
47
48
        $a = new DDC729A();
49
        $a->id = $aId;
50
51
        $this->assertInstanceOf(ArrayCollection::class, $a->related);
52
53
        $a = $this->_em->merge($a);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

53
        $a = /** @scrutinizer ignore-deprecated */ $this->_em->merge($a);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
54
55
        $this->assertInstanceOf(PersistentCollection::class, $a->related);
56
57
        $this->assertFalse($a->related->isInitialized(), "Collection should not be marked initialized.");
0 ignored issues
show
Bug introduced by
The method isInitialized() does not exist on Doctrine\Common\Collections\ArrayCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $this->assertFalse($a->related->/** @scrutinizer ignore-call */ isInitialized(), "Collection should not be marked initialized.");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
        $this->assertFalse($a->related->isDirty(), "Collection should not be marked as dirty.");
0 ignored issues
show
Bug introduced by
The method isDirty() does not exist on Doctrine\Common\Collections\ArrayCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        $this->assertFalse($a->related->/** @scrutinizer ignore-call */ isDirty(), "Collection should not be marked as dirty.");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
60
        $this->_em->flush();
61
        $this->_em->clear();
62
63
        $a = $this->_em->find(DDC729A::class, $aId);
64
        $this->assertEquals(1, count($a->related));
65
    }
66
67
    public function testUnidirectionalMergeManyToMany()
68
    {
69
        $a = new DDC729A();
70
        $b1 = new DDC729B();
71
        $b2 = new DDC729B();
72
        $a->related[] = $b1;
73
74
        $this->_em->persist($a);
75
        $this->_em->persist($b1);
76
        $this->_em->persist($b2);
77
        $this->_em->flush();
78
        $this->_em->clear();
79
        $aId = $a->id;
80
81
        $a = new DDC729A();
82
        $a->id = $aId;
83
84
        $a = $this->_em->merge($a);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

84
        $a = /** @scrutinizer ignore-deprecated */ $this->_em->merge($a);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
85
86
        $a->related->set(0, $this->_em->merge($b1));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

86
        $a->related->set(0, /** @scrutinizer ignore-deprecated */ $this->_em->merge($b1));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
87
88
        $a->related->set(1, $this->_em->merge($b2));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

88
        $a->related->set(1, /** @scrutinizer ignore-deprecated */ $this->_em->merge($b2));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
89
90
        $this->_em->flush();
91
        $this->_em->clear();
92
93
        $a = $this->_em->find(DDC729A::class, $aId);
94
        $this->assertEquals(2, count($a->related));
95
    }
96
97
    public function testBidirectionalMergeManyToMany()
98
    {
99
        $a = new DDC729A();
100
        $b1 = new DDC729B();
101
        $b2 = new DDC729B();
102
        $a->related[] = $b1;
103
104
        $this->_em->persist($a);
105
        $this->_em->persist($b1);
106
        $this->_em->persist($b2);
107
        $this->_em->flush();
108
        $this->_em->clear();
109
        $aId = $a->id;
110
111
        $a = new DDC729A();
112
        $a->id = $aId;
113
114
        $a = $this->_em->merge($a);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

114
        $a = /** @scrutinizer ignore-deprecated */ $this->_em->merge($a);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
115
116
        $a->related->set(0, $this->_em->merge($b1));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

116
        $a->related->set(0, /** @scrutinizer ignore-deprecated */ $this->_em->merge($b1));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
117
        $b1->related->set(0, $a);
118
119
        $a->related->set(1, $this->_em->merge($b2));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

119
        $a->related->set(1, /** @scrutinizer ignore-deprecated */ $this->_em->merge($b2));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
120
        $b2->related->set(0, $a);
121
122
        $this->_em->flush();
123
        $this->_em->clear();
124
125
        $a = $this->_em->find(DDC729A::class, $aId);
126
        $this->assertEquals(2, count($a->related));
127
    }
128
129
    public function testBidirectionalMultiMergeManyToMany()
130
    {
131
        $a = new DDC729A();
132
        $b1 = new DDC729B();
133
        $b2 = new DDC729B();
134
        $a->related[] = $b1;
135
136
        $this->_em->persist($a);
137
        $this->_em->persist($b1);
138
        $this->_em->persist($b2);
139
        $this->_em->flush();
140
        $this->_em->clear();
141
        $aId = $a->id;
142
143
        $a = new DDC729A();
144
        $a->id = $aId;
145
146
        $a = $this->_em->merge($a);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

146
        $a = /** @scrutinizer ignore-deprecated */ $this->_em->merge($a);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
147
148
        $a->related->set(0, $this->_em->merge($b1));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

148
        $a->related->set(0, /** @scrutinizer ignore-deprecated */ $this->_em->merge($b1));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
149
        $b1->related->set(0, $this->_em->merge($a));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

149
        $b1->related->set(0, /** @scrutinizer ignore-deprecated */ $this->_em->merge($a));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
150
151
        $a->related->set(1, $this->_em->merge($b2));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

151
        $a->related->set(1, /** @scrutinizer ignore-deprecated */ $this->_em->merge($b2));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
152
        $b2->related->set(0, $this->_em->merge($a));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::merge() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

152
        $b2->related->set(0, /** @scrutinizer ignore-deprecated */ $this->_em->merge($a));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
153
154
        $this->_em->flush();
155
        $this->_em->clear();
156
157
        $a = $this->_em->find(DDC729A::class, $aId);
158
        $this->assertEquals(2, count($a->related));
159
    }
160
}
161
162
/**
163
 * @Entity
164
 */
165
class DDC729A
166
{
167
    /** @Id @GeneratedValue @Column(type="integer") */
168
    public $id;
169
170
    /** @ManyToMany(targetEntity="DDC729B", inversedBy="related") */
171
    public $related;
172
173
    public function __construct()
174
    {
175
        $this->related = new \Doctrine\Common\Collections\ArrayCollection();
176
    }
177
}
178
179
/**
180
 * @Entity
181
 */
182
class DDC729B
183
{
184
    /** @Id @GeneratedValue @Column(type="integer") */
185
    public $id;
186
187
    /** @ManyToMany(targetEntity="DDC729B", mappedBy="related") */
188
    public $related;
189
190
    public function __construct()
191
    {
192
        $this->related = new \Doctrine\Common\Collections\ArrayCollection();
193
    }
194
}
195