@@ -13,10 +13,11 @@ class GH2730Test extends BaseTestCase
1313{
1414 public function testUniqueObjectIdentifier (): void
1515 {
16- $ document = new GH2730Document ();
16+ $ document = new GH2730 ();
1717 $ oid = spl_object_hash ($ document );
1818 $ this ->dm ->persist ($ document );
1919 $ this ->dm ->flush ();
20+ $ id = $ document ->id ;
2021
2122 // Remove the document
2223 $ this ->dm ->remove ($ document );
@@ -26,57 +27,72 @@ public function testUniqueObjectIdentifier(): void
2627 unset($ document );
2728
2829 // Create a new document
29- $ document = new GH2730Document ();
30+ $ document = new GH2730 ();
3031 $ this ->dm ->persist ($ document );
32+
33+ // If this assertion fails in a future version of PHP, this test case can be skipped.
34+ self ::assertSame ($ oid , spl_object_hash ($ document ), 'PHP created a new object with the same object hash ' );
35+ self ::assertNotEquals ($ document ->id , $ id , 'New ID generated ' );
36+ self ::assertCount (1 , $ this ->dm ->getUnitOfWork ()->getScheduledDocumentInsertions ());
37+ self ::assertCount (0 , $ this ->dm ->getUnitOfWork ()->getScheduledDocumentUpserts ());
38+
3139 $ this ->dm ->flush ();
3240
3341 self ::assertSame (1 , $ this ->countDocuments ());
34-
35- // If this assertion fails in a future version of PHP, this test case can be skipped.
36- self ::assertSame ($ oid , spl_object_hash ($ document ), 'PHP created a new object wit the same object hash ' );
3742 }
3843
3944 public function testRemoveFlushPersist (): void
4045 {
41- $ document = new GH2730Document ();
46+ $ document = new GH2730 ();
4247 $ this ->dm ->persist ($ document );
4348 $ this ->dm ->flush ();
49+ $ id = $ document ->id ;
4450
4551 // Remove the document
4652 $ this ->dm ->remove ($ document );
4753 $ this ->dm ->flush ();
4854
4955 // Re-persist the same document
5056 $ this ->dm ->persist ($ document );
57+ self ::assertEquals ($ document ->id , $ id , 'ID not regenerated ' );
58+ self ::assertCount (0 , $ this ->dm ->getUnitOfWork ()->getScheduledDocumentInsertions ());
59+ self ::assertCount (1 , $ this ->dm ->getUnitOfWork ()->getScheduledDocumentUpserts ());
60+
5161 $ this ->dm ->flush ();
5262
5363 self ::assertSame (1 , $ this ->countDocuments ());
5464 }
5565
5666 public function testRemovePersist (): void
5767 {
58- $ document = new GH2730Document ();
68+ $ document = new GH2730 ();
5969 $ this ->dm ->persist ($ document );
6070 $ this ->dm ->flush ();
71+ $ id = $ document ->id ;
6172
6273 // Remove the document
6374 $ this ->dm ->remove ($ document );
6475
6576 // Re-persist the same document
6677 $ this ->dm ->persist ($ document );
78+
79+ self ::assertEquals ($ document ->id , $ id , 'ID not regenerated ' );
80+ self ::assertCount (0 , $ this ->dm ->getUnitOfWork ()->getScheduledDocumentInsertions ());
81+ self ::assertCount (1 , $ this ->dm ->getUnitOfWork ()->getScheduledDocumentUpserts ());
82+
6783 $ this ->dm ->flush ();
6884
6985 self ::assertSame (1 , $ this ->countDocuments ());
7086 }
7187
7288 private function countDocuments (): int
7389 {
74- return $ this ->dm ->getDocumentCollection (GH2730Document ::class)->countDocuments ();
90+ return $ this ->dm ->getDocumentCollection (GH2730 ::class)->countDocuments ();
7591 }
7692}
7793
7894#[ODM \Document]
79- class GH2730Document
95+ class GH2730
8096{
8197 #[ODM \Id]
8298 public ?string $ id = null ;
0 commit comments