Completed
Pull Request — 2.7 (#8036)
by Maciej
06:26
created

GH8031Invoice::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
class GH8031Test extends OrmFunctionalTestCase
11
{
12
    protected function setUp()
13
    {
14
        parent::setUp();
15
16
        $this->setUpEntitySchema([
17
            GH8031Invoice::class,
18
        ]);
19
    }
20
21
    public function testEntityIsFetched()
22
    {
23
        $entity = new GH8031Invoice(new GH8031InvoiceCode(1, 2020));
24
        $this->_em->persist($entity);
25
        $this->_em->flush();
26
        $this->_em->clear();
27
28
        /** @var GH8031Invoice $fetched */
29
        $fetched = $this->_em->find(GH8031Invoice::class, $entity->getId());
30
        $this->assertInstanceOf(GH8031Invoice::class, $fetched);
31
        $this->assertSame(1, $fetched->getCode()->getNumber());
32
        $this->assertSame(2020, $fetched->getCode()->getYear());
33
    }
34
}
35
36
/**
37
 * @Embeddable
38
 */
39
class GH8031InvoiceCode extends GH8031AbstractYearSequenceValue
40
{
41
42
}
43
44
/**
45
 * @Embeddable
46
 */
47
abstract class GH8031AbstractYearSequenceValue
48
{
49
    /**
50
     * @Column(type="integer", name="number", length=6)
51
     *
52
     * @var int
53
     */
54
    protected $number;
55
56
    /**
57
     * @Column(type="smallint", name="year", length=4)
58
     *
59
     * @var int
60
     */
61
    protected $year;
62
63
    public function __construct(int $number, int $year)
64
    {
65
        $this->number = $number;
66
        $this->year = $year;
67
    }
68
69
    public function getNumber(): int
70
    {
71
        return $this->number;
72
    }
73
74
    public function getYear(): int
75
    {
76
        return $this->year;
77
    }
78
}
79
80
/**
81
 * @Entity
82
 */
83
class GH8031Invoice
84
{
85
    /**
86
     * @Id
87
     * @GeneratedValue
88
     * @Column(type="integer")
89
     */
90
    private $id;
91
92
    /**
93
     * @Embedded(class=GH8031InvoiceCode::class)
94
     *
95
     * @var GH8031InvoiceCode
96
     */
97
    private $code;
98
99
    public function __construct(GH8031InvoiceCode $code)
100
    {
101
        $this->code = $code;
102
    }
103
104
    public function getId()
105
    {
106
        return $this->id;
107
    }
108
109
    public function getCode(): GH8031InvoiceCode
110
    {
111
        return $this->code;
112
    }
113
}
114