Completed
Pull Request — 2.7 (#8090)
by
unknown
07:58
created

GH8089Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testEntityIsFetched() 0 15 1
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 GH8089Test extends OrmFunctionalTestCase
10
{
11
    protected function setUp()
12
    {
13
        parent::setUp();
14
15
        $this->setUpEntitySchema([
16
            GH8089Invoice::class,
17
        ]);
18
    }
19
20
    public function testEntityIsFetched()
21
    {
22
        $entity = new GH8089Invoice(new GH8089InvoiceCode(1, 2020));
23
        $this->_em->persist($entity);
24
        $this->_em->flush();
25
        $this->_em->clear();
26
27
        /** @var GH8089Invoice $fetched */
28
        $fetched = $this->_em->find(GH8089Invoice::class, $entity->getId());
29
        $this->assertInstanceOf(GH8089Invoice::class, $fetched);
30
31
        $this->assertSame(1, $fetched->getCode()->getNumber());
32
        $this->assertSame(2020, $fetched->getCode()->getYear());
33
34
        $this->_em->clear();
35
    }
36
}
37
38
/**
39
 * @Embeddable
40
 */
41
class GH8089InvoiceCode extends GH8089AbstractYearSequenceValue
42
{
43
}
44
45
/**
46
 * @Embeddable
47
 * @MappedSuperclass
48
 */
49
abstract class GH8089AbstractYearSequenceValue
50
{
51
    /**
52
     * @Column(type="integer", name="number", length=6)
53
     * @var int
54
     */
55
    protected $number;
56
57
    /**
58
     * @Column(type="smallint", name="year", length=4)
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 GH8089Invoice
84
{
85
    /**
86
     * @Id
87
     * @GeneratedValue
88
     * @Column(type="integer")
89
     */
90
    private $id;
91
92
    /**
93
     * @Embedded(class=GH8089InvoiceCode::class)
94
     * @var GH8089InvoiceCode
95
     */
96
    private $code;
97
98
    public function __construct(GH8089InvoiceCode $code)
99
    {
100
        $this->code = $code;
101
    }
102
103
    public function getId()
104
    {
105
        return $this->id;
106
    }
107
108
    public function getCode() : GH8089InvoiceCode
109
    {
110
        return $this->code;
111
    }
112
}
113