From bd8b0c5ff6c8779728c26f4de30c9e96ac47b5f6 Mon Sep 17 00:00:00 2001 From: David Solc Date: Thu, 27 Jan 2022 05:51:05 +0100 Subject: [PATCH] test: nullable property --- .../Models/ReadonlyProperties/SimpleBook.php | 2 +- .../ORM/Functional/ReadonlyPropertiesTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Models/ReadonlyProperties/SimpleBook.php b/tests/Doctrine/Tests/Models/ReadonlyProperties/SimpleBook.php index 87e966682af..b31386c420c 100644 --- a/tests/Doctrine/Tests/Models/ReadonlyProperties/SimpleBook.php +++ b/tests/Doctrine/Tests/Models/ReadonlyProperties/SimpleBook.php @@ -19,7 +19,7 @@ class SimpleBook private readonly int $id; #[Column] - private readonly string $title; + public readonly string $title; #[ManyToOne, JoinColumn(nullable: false)] private readonly Author $author; diff --git a/tests/Doctrine/Tests/ORM/Functional/ReadonlyPropertiesTest.php b/tests/Doctrine/Tests/ORM/Functional/ReadonlyPropertiesTest.php index 17aa2306df6..1139ae2342b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReadonlyPropertiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReadonlyPropertiesTest.php @@ -108,4 +108,22 @@ public function testEntityWithManyToMany(): void self::assertEquals($bookId, $book->getId()); self::assertSame('Jane Austen', $book->getAuthors()[0]->getName()); } + + public function testEntityProxy(): void + { + $connection = $this->_em->getConnection(); + + $connection->insert('author', ['name' => 'Jane Austen']); + $authorId = $connection->lastInsertId(); + + $connection->insert('simple_book', ['title' => 'Pride and Prejudice', 'author_id' => $authorId]); + $bookId = $connection->lastInsertId(); + + $proxyBook = $this->_em->getReference(SimpleBook::class, $bookId); + + self::assertSame('Pride and Prejudice', $proxyBook->title); + self::assertEquals($bookId, $proxyBook->getId()); + self::assertSame('Jane Austen', $proxyBook->getAuthor()->getName()); + } + }