Completed
Pull Request — master (#7722)
by Lukas
09:30
created

GH7719Wife::setHusband()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\ORM\Annotation as ORM;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
class GH7719Test extends OrmFunctionalTestCase
11
{
12
    protected function setUp() : void
13
    {
14
        parent::setUp();
15
16
        $this->setUpEntitySchema([GH7719Husband::class, GH7719Wife::class]);
17
    }
18
19
    public function testThatChangingTheEntityFromTheInverseSideInAOneToOneRelationDoesNotCauseUniqueIndexError()
20
    {
21
        $wife = new GH7719Wife();
22
23
        $wife->setHusband(new GH7719Husband());
24
25
        $this->em->persist($wife);
26
        $this->em->flush();
27
28
        $this->em->remove($wife->getHusband());
29
        $wife->setHusband(new GH7719Husband());
30
31
        $this->em->flush();
32
    }
33
}
34
35
/**
36
 * @ORM\Entity
37
 */
38
class GH7719Husband
39
{
40
    /**
41
     * @ORM\Id
42
     * @ORM\Column(type="integer")
43
     * @ORM\GeneratedValue
44
     */
45
    private $id;
0 ignored issues
show
introduced by
The private property $id is not used, and could be removed.
Loading history...
46
47
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH7719Husband::$wife with single line content, use one-line comment instead.
Loading history...
48
     * @ORM\OneToOne(targetEntity=GH7719Wife::class, inversedBy="husband")
49
     */
50
    private $wife;
51
52
    public function setWife(GH7719Wife $wife): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
53
    {
54
        $this->wife = $wife;
55
    }
56
}
57
58
/**
59
 * @ORM\Entity
60
 */
61
class GH7719Wife
62
{
63
    /**
64
     * @ORM\Id
65
     * @ORM\Column(type="integer")
66
     * @ORM\GeneratedValue
67
     */
68
    private $id;
69
70
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\Tests\ORM\Functional\Ticket\GH7719Wife::$husband with single line content, use one-line comment instead.
Loading history...
71
     * @ORM\OneToOne(targetEntity=GH7719Husband::class, mappedBy="wife", cascade={"persist"})
72
     */
73
    private $husband;
74
75
    public function setHusband(GH7719Husband $husband): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
76
    {
77
        $this->husband = $husband;
78
        $this->husband->setWife($this);
79
    }
80
81
    public function getHusband(): GH7719Husband
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
82
    {
83
        return $this->husband;
84
    }
85
}
86