Failed Conditions
Pull Request — 2.7 (#8036)
by Maciej
07:43
created

GH8031Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
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));
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 GH8031InvoiceCode extends GH8031AbstractYearSequenceValue
45
{
46
}
47
48
/**
49
 * @Embeddable
50
 */
51
abstract class GH8031AbstractYearSequenceValue
52
{
53
    /**
54
     * @Column(type="integer", name="number", length=6)
55
     * @var int
56
     */
57
    protected $number;
58
59
    /**
60
     * @Column(type="smallint", name="year", length=4)
61
     * @var int
62
     */
63
    protected $year;
64
65
    public function __construct(int $number, int $year)
66
    {
67
        $this->number = $number;
68
        $this->year   = $year;
69
    }
70
71
    public function getNumber() : int
72
    {
73
        return $this->number;
74
    }
75
76
    public function getYear() : int
77
    {
78
        return $this->year;
79
    }
80
}
81
82
/**
83
 * @Entity
84
 */
85
class GH8031Invoice
86
{
87
    /**
88
     * @Id
89
     * @GeneratedValue
90
     * @Column(type="integer")
91
     */
92
    private $id;
93
94
    /**
95
     * @Embedded(class=GH8031InvoiceCode::class)
96
     * @var GH8031InvoiceCode
97
     */
98
    private $code;
99
100
    public function __construct(GH8031InvoiceCode $code)
101
    {
102
        $this->code = $code;
103
    }
104
105
    public function getId()
106
    {
107
        return $this->id;
108
    }
109
110
    public function getCode() : GH8031InvoiceCode
111
    {
112
        return $this->code;
113
    }
114
}
115