diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ed17d8..45de81d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,9 @@ jobs: php: - '7.4' - '8.0' + - '8.1' + - '8.2' + - '8.3' steps: - name: Check out code diff --git a/composer.json b/composer.json index 19db2bc..050fbaa 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "php": "^7.4 || ^8.0", "doctrine/annotations": "^1.10", - "doctrine/collections": "^1.6", + "doctrine/collections": "^1.6.8", "doctrine/orm": "^2.9", "doctrine/persistence": "^1.3 || ^2.0", "symfony/polyfill-php80": "^1.20" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e5f3ee0..50ed9d2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -35,6 +35,11 @@ parameters: count: 1 path: tests/Entities/GrabBag.php + - + message: "#^Class Firehed\\\\Mocktrine\\\\Entities\\\\ReadonlyGeneratedId has an uninitialized readonly property \\$id\\. Assign it in the constructor\\.$#" + count: 1 + path: tests/Entities/ReadonlyGeneratedId.php + - message: "#^Property Firehed\\\\Mocktrine\\\\Entities\\\\StringId\\:\\:\\$id is never written, only read\\.$#" count: 1 diff --git a/tests/Entities/ReadonlyConstructorId.php b/tests/Entities/ReadonlyConstructorId.php new file mode 100644 index 0000000..f45189a --- /dev/null +++ b/tests/Entities/ReadonlyConstructorId.php @@ -0,0 +1,30 @@ +id = bin2hex(random_bytes(10)); + } +} diff --git a/tests/Entities/ReadonlyGeneratedId.php b/tests/Entities/ReadonlyGeneratedId.php new file mode 100644 index 0000000..ca67bde --- /dev/null +++ b/tests/Entities/ReadonlyGeneratedId.php @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/tests/Entities/XmlMappings/Firehed.Mocktrine.Entities.ReadonlyGeneratedId.dcm.xml b/tests/Entities/XmlMappings/Firehed.Mocktrine.Entities.ReadonlyGeneratedId.dcm.xml new file mode 100644 index 0000000..95b2398 --- /dev/null +++ b/tests/Entities/XmlMappings/Firehed.Mocktrine.Entities.ReadonlyGeneratedId.dcm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/tests/InMemoryEntityManagerTest.php b/tests/InMemoryEntityManagerTest.php index f5d7c4c..40f944a 100644 --- a/tests/InMemoryEntityManagerTest.php +++ b/tests/InMemoryEntityManagerTest.php @@ -182,4 +182,28 @@ public function testInteractionWithMultipleEntities(): void $foundStringId = $em->find(Entities\StringId::class, $stringId->getId()); $this->assertSame($foundStringId, $stringId); } + + public function testGeneratedReadonlyIdWorks(): void + { + if (version_compare(PHP_VERSION, '8.1.0', '<')) { + $this->markTestSkipped('Readonly properties need 8.1+'); + } + $rgid = new Entities\ReadonlyGeneratedId(); + $em = $this->getEntityManager(); + $em->persist($rgid); + $em->flush(); + $this->assertIsInt($rgid->id); + } + + public function testConstructorAssignedReadonlyIdWorks(): void + { + if (version_compare(PHP_VERSION, '8.1.0', '<')) { + $this->markTestSkipped('Readonly properties need 8.1+'); + } + $rgid = new Entities\ReadonlyConstructorId(); + $em = $this->getEntityManager(); + $em->persist($rgid); + $em->flush(); + $this->assertIsString($rgid->id); + } }