Failed Conditions
Pull Request — 2.7 (#8036)
by Benjamin
07:22
created

GH8031Test::testEntityIsFetched()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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