Completed
Push — master ( b59b96...3dfc18 )
by Marco
14:55
created

DDC3303Test::testEmbeddedObjectsAreAlsoInherited()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
namespace Doctrine\Tests\ORM\Functional\Ticket;
3
4
use Doctrine\Tests\OrmFunctionalTestCase;
5
6
class DDC3303Test extends OrmFunctionalTestCase
7
{
8
    protected function setUp()
9
    {
10
        parent::setUp();
11
12
        $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC3303Employee::class)]);
13
    }
14
15
    /**
16
     * @group 4097
17
     * @group 4277
18
     * @group 5867
19
     *
20
     * When using an embedded field in an inheritance, private properties should also be inherited.
21
     */
22
    public function testEmbeddedObjectsAreAlsoInherited()
23
    {
24
        $employee = new DDC3303Employee(
25
            'John Doe',
26
            new DDC3303Address('Somewhere', 123, 'Over the rainbow'),
27
            'Doctrine Inc'
28
        );
29
30
        $this->_em->persist($employee);
31
        $this->_em->flush();
32
        $this->_em->clear();
33
34
        self::assertEquals($employee, $this->_em->find(DDC3303Employee::class, 'John Doe'));
35
    }
36
}
37
38
/** @MappedSuperclass */
39
abstract class DDC3303Person
40
{
41
    /** @Id @GeneratedValue(strategy="NONE") @Column(type="string") @var string */
42
    private $name;
43
44
    /** @Embedded(class="DDC3303Address") @var DDC3303Address */
45
    private $address;
46
47
    public function __construct($name, DDC3303Address $address)
48
    {
49
        $this->name    = $name;
50
        $this->address = $address;
51
    }
52
}
53
54
/**
55
 * @Embeddable
56
 */
57
class DDC3303Address
58
{
59
    /** @Column(type="string") @var string */
60
    private $street;
61
62
    /** @Column(type="integer") @var int */
63
    private $number;
64
65
    /** @Column(type="string") @var string */
66
    private $city;
67
68
    public function __construct($street, $number, $city)
69
    {
70
        $this->street = $street;
71
        $this->number = $number;
72
        $this->city   = $city;
73
    }
74
}
75
76
/**
77
 * @Entity
78
 * @Table(name="ddc3303_employee")
79
 */
80
class DDC3303Employee extends DDC3303Person
81
{
82
    /** @Column(type="string") @var string */
83
    private $company;
84
85
    public function __construct($name, DDC3303Address $address, $company)
86
    {
87
        parent::__construct($name, $address);
88
89
        $this->company = $company;
90
    }
91
}
92