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

DDC3597Test   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 47
dl 0
loc 99
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToOneUninitializedAssociations() 0 38 1
A testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToManyUninitializedAssociations() 0 36 1
A ensureTestGeneratedDeprecationMessages() 0 3 1
A setUp() 0 5 1
1
<?php
2
3
use Doctrine\Tests\Models\DDC3699\DDC3699RelationOne;
4
use Doctrine\Tests\Models\DDC3699\DDC3699RelationMany;
5
use Doctrine\Tests\Models\DDC3699\DDC3699Child;
6
use Doctrine\Tests\VerifyDeprecations;
7
8
/**
9
 * @group DDC-3699
10
 */
11
class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase
12
{
13
    use VerifyDeprecations;
14
15
    protected function setUp()
16
    {
17
        $this->useModelSet('ddc3699');
18
19
        parent::setUp();
20
    }
21
22
    /** @after */
23
    public function ensureTestGeneratedDeprecationMessages() : void
24
    {
25
        $this->assertHasDeprecationMessages();
26
    }
27
28
    /**
29
     * @group DDC-3699
30
     */
31
    public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToOneUninitializedAssociations()
32
    {
33
        $id = 1;
34
35
        $child = new DDC3699Child();
36
37
        $child->id          = $id;
38
        $child->childField  = 'childValue';
39
        $child->parentField = 'parentValue';
40
41
        $relation = new DDC3699RelationOne();
42
43
        $relation->id       = $id;
44
        $relation->child    = $child ;
45
        $child->oneRelation = $relation;
46
47
        $this->_em->persist($relation);
48
        $this->_em->persist($child);
49
        $this->_em->flush();
50
        $this->_em->clear();
51
52
        // fixtures loaded
53
        /* @var $unManagedChild DDC3699Child */
54
        $unManagedChild = $this->_em->find(DDC3699Child::class, $id);
55
56
        $this->_em->detach($unManagedChild);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::detach() 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

56
        /** @scrutinizer ignore-deprecated */ $this->_em->detach($unManagedChild);

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...
57
58
        // make it managed again
59
        $this->_em->find(DDC3699Child::class, $id);
60
61
        $unManagedChild->childField  = 'modifiedChildValue';
62
        $unManagedChild->parentField = 'modifiedParentValue';
63
64
        /* @var $mergedChild DDC3699Child */
65
        $mergedChild = $this->_em->merge($unManagedChild);
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

65
        $mergedChild = /** @scrutinizer ignore-deprecated */ $this->_em->merge($unManagedChild);

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...
66
67
        $this->assertSame($mergedChild->childField, 'modifiedChildValue');
68
        $this->assertSame($mergedChild->parentField, 'modifiedParentValue');
69
    }
70
71
    /**
72
     * @group DDC-3699
73
     */
74
    public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToManyUninitializedAssociations()
75
    {
76
        $id = 2;
77
78
        $child = new DDC3699Child();
79
80
        $child->id          = $id;
81
        $child->childField  = 'childValue';
82
        $child->parentField = 'parentValue';
83
84
        $relation = new DDC3699RelationMany();
85
86
        $relation->id       = $id;
87
        $relation->child    = $child ;
88
        $child->relations[] = $relation;
89
90
        $this->_em->persist($relation);
91
        $this->_em->persist($child);
92
        $this->_em->flush();
93
        $this->_em->clear();
94
95
        /* @var $unmanagedChild DDC3699Child */
96
        $unmanagedChild = $this->_em->find(DDC3699Child::class, $id);
97
        $this->_em->detach($unmanagedChild);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::detach() 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

97
        /** @scrutinizer ignore-deprecated */ $this->_em->detach($unmanagedChild);

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...
98
99
        // make it managed again
100
        $this->_em->find(DDC3699Child::class, $id);
101
102
        $unmanagedChild->childField  = 'modifiedChildValue';
103
        $unmanagedChild->parentField = 'modifiedParentValue';
104
105
        /* @var $mergedChild DDC3699Child */
106
        $mergedChild = $this->_em->merge($unmanagedChild);
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

106
        $mergedChild = /** @scrutinizer ignore-deprecated */ $this->_em->merge($unmanagedChild);

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...
107
108
        $this->assertSame($mergedChild->childField, 'modifiedChildValue');
109
        $this->assertSame($mergedChild->parentField, 'modifiedParentValue');
110
    }
111
}
112