From f3402cd52867623d1e9b23827c80909552aedac0 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Sun, 23 Feb 2020 11:38:11 +0100 Subject: [PATCH] Add test case --- .../ORM/Functional/Ticket/GH8031Test.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH8031Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8031Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8031Test.php new file mode 100644 index 00000000000..3ff242ac4b6 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8031Test.php @@ -0,0 +1,114 @@ +setUpEntitySchema([ + GH8031Invoice::class, + ]); + } + + public function testEntityIsFetched() + { + $entity = new GH8031Invoice(new GH8031InvoiceCode(1, 2020)); + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + /** @var GH8031Invoice $fetched */ + $fetched = $this->_em->find(GH8031Invoice::class, $entity->getId()); + $this->assertInstanceOf(GH8031Invoice::class, $fetched); + $this->assertSame(1, $fetched->getCode()->getNumber()); + $this->assertSame(2020, $fetched->getCode()->getYear()); + + $this->_em->clear(); + $this->assertCount( + 1, + $this->_em->getRepository(GH8031Invoice::class)->findBy([], ['code.number' => 'ASC']) + ); + } +} + +/** + * @Embeddable + */ +class GH8031InvoiceCode extends GH8031AbstractYearSequenceValue +{ +} + +/** + * @Embeddable + */ +abstract class GH8031AbstractYearSequenceValue +{ + /** + * @Column(type="integer", name="number", length=6) + * @var int + */ + protected $number; + + /** + * @Column(type="smallint", name="year", length=4) + * @var int + */ + protected $year; + + public function __construct(int $number, int $year) + { + $this->number = $number; + $this->year = $year; + } + + public function getNumber() : int + { + return $this->number; + } + + public function getYear() : int + { + return $this->year; + } +} + +/** + * @Entity + */ +class GH8031Invoice +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + private $id; + + /** + * @Embedded(class=GH8031InvoiceCode::class) + * @var GH8031InvoiceCode + */ + private $code; + + public function __construct(GH8031InvoiceCode $code) + { + $this->code = $code; + } + + public function getId() + { + return $this->id; + } + + public function getCode() : GH8031InvoiceCode + { + return $this->code; + } +}