Failed Conditions
Pull Request — master (#6649)
by Marco
140:45 queued 75:42
created

GH6638Customer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\Functional\Ticket;
4
5
use Doctrine\ORM\Tools\ToolsException;
6
use Doctrine\Tests\OrmFunctionalTestCase;
7
8
/**
9
 * @group #6638
10
 * @group #6648
11
 */
12
final class GH6638Test extends OrmFunctionalTestCase
13
{
14 View Code Duplication
    public function setUp() : void
15
    {
16
        parent::setUp();
17
18
        try {
19
            $this->_schemaTool->createSchema([
20
                $this->_em->getClassMetadata(GH6638Customer::class),
21
                $this->_em->getClassMetadata(GH6638Cart::class),
22
            ]);
23
        } catch (ToolsException $ignored) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
24
        }
25
    }
26
27 View Code Duplication
    public function testFindByDoesNotReHydrateAssociation() : void
28
    {
29
        $initialCustomer = new GH6638Customer();
30
        $initialCart     = new GH6638Cart();
31
32
        $initialCustomer->cart = $initialCart;
33
        $initialCart->customer = $initialCustomer;
34
35
        $this->_em->persist($initialCustomer);
36
        $this->_em->persist($initialCart);
37
        $this->_em->flush();
38
        $this->_em->clear();
39
40
        $repository = $this->_em->getRepository(GH6638Customer::class);
41
42
        $customer = $repository->find($initialCustomer->id);
43
44
        self::assertInstanceOf(GH6638Cart::class, $customer->cart);
45
46
        $customer->cart = null;
47
48
        self::assertNull($customer->cart);
49
50
        $repository->findBy(['id' => $initialCustomer->id]);
51
52
        self::assertNull($customer->cart);
53
    }
54
55 View Code Duplication
    public function testFindOneByDoesNotReHydrateAssociation() : void
56
    {
57
        $initialCustomer = new GH6638Customer();
58
        $initialCart     = new GH6638Cart();
59
60
        $initialCustomer->cart = $initialCart;
61
        $initialCart->customer = $initialCustomer;
62
63
        $this->_em->persist($initialCustomer);
64
        $this->_em->persist($initialCart);
65
        $this->_em->flush();
66
        $this->_em->clear();
67
68
        $repository = $this->_em->getRepository(GH6638Customer::class);
69
70
        $customer = $repository->find($initialCustomer->id);
71
72
        self::assertInstanceOf(GH6638Cart::class, $customer->cart);
73
74
        $customer->cart = null;
75
76
        self::assertNull($customer->cart);
77
78
        $repository->findOneBy(['id' => $initialCustomer->id]);
79
80
        self::assertNull($customer->cart);
81
    }
82
}
83
84
/** @Entity */
85
class GH6638Customer
86
{
87
    /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
88
    public $id;
89
90
    /** @OneToOne(targetEntity=GH6638Cart::class, mappedBy="customer") */
91
    public $cart;
92
93
    public function __construct()
94
    {
95
        $this->id = uniqid(self::class, true);
96
    }
97
}
98
99
/** @Entity */
100
class GH6638Cart
101
{
102
    /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
103
    public $id;
104
105
    /**
106
     * @OneToOne(targetEntity=GH6638Customer::class, inversedBy="cart")
107
     */
108
    public $customer;
109
110
    public function __construct()
111
    {
112
        $this->id = uniqid(self::class, true);
113
    }
114
}
115