Skip to content

Commit f3402cd

Browse files
committed
Add test case
1 parent e04a795 commit f3402cd

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
}

0 commit comments

Comments
 (0)