Test Failed
Pull Request — master (#6648)
by Johan de
65:41
created

GH6638Test::testFetchingOfOneToOneRelations()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
7
final class GH6638Test extends OrmFunctionalTestCase
8
{
9
    public function setUp() : void
10
    {
11
        parent::setUp();
12
13
        $this->_schemaTool->createSchema([
14
            $this->_em->getClassMetadata(GH6638Customer::class),
15
            $this->_em->getClassMetadata(GH6638Cart::class),
16
        ]);
17
    }
18
19
    public function testFetchingOfOneToOneRelations() : void
20
    {
21
        $initialCustomer = new GH6638Customer();
22
23
        $initialCart = new GH6638Cart();
24
        $initialCustomer->cart = $initialCart;
25
        $initialCart->customer = $initialCustomer;
26
27
        $this->_em->persist($initialCustomer);
28
        $this->_em->persist($initialCart);
29
        $this->_em->flush();
30
        $this->_em->clear();
31
32
        $repository = $this->_em->getRepository(GH6638Customer::class);
33
34
        $customer = $repository->find($initialCustomer->id);
35
36
        $this->assertInstanceOf(GH6638Cart::class, $customer->cart);
37
38
        $customer->cart = null;
39
40
        $this->assertNull($customer->cart);
41
42
        $repository->findBy(['id' => $initialCustomer->id]);
43
44
        $this->assertNull($customer->cart);
45
    }
46
}
47
48
/**
49
 * @Entity
50
 */
51
class GH6638Customer
52
{
53
    /**
54
     * @Id
55
     * @Column(type="integer")
56
     * @GeneratedValue
57
     */
58
    public $id;
59
60
    /**
61
     * @OneToOne(targetEntity="GH6638Cart", mappedBy="customer")
62
     */
63
    public $cart;
64
}
65
66
/**
67
 * @Entity
68
 */
69
class GH6638Cart
70
{
71
    /**
72
     * @Id
73
     * @Column(type="integer")
74
     * @GeneratedValue
75
     */
76
    public $id;
77
78
    /**
79
     * @OneToOne(targetEntity="GH6638Customer", inversedBy="cart")
80
     * @JoinColumn()
81
     */
82
    public $customer;
83
}
84