File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed
Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,10 @@ private function getSkippedProperties(ClassMetadata $metadata): array
101101 continue ;
102102 }
103103
104+ if ($ property ->isStatic ()) {
105+ continue ;
106+ }
107+
104108 $ skippedProperties [] = $ property ;
105109 }
106110
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Documents ;
6+
7+ use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
8+
9+ #[ODM \Document]
10+ class DocumentWithStaticProperty
11+ {
12+ #[ODM \Id]
13+ public string $ id ;
14+
15+ public static string $ foo = 'bar ' ;
16+
17+ // We need at least one mapped field to avoid the native lazy object to be
18+ // switched to "initialized" state immediately after setting all its properties.
19+ #[ODM \Field]
20+ public string $ mappedField ;
21+ }
Original file line number Diff line number Diff line change 1515use Doctrine \ODM \MongoDB \Tests \BaseTestCase ;
1616use Documents \Account ;
1717use Documents \Address ;
18+ use Documents \DocumentWithStaticProperty ;
1819use Documents \DocumentWithUnmappedProperties ;
1920use Documents \Group ;
2021use Documents \Phonenumber ;
@@ -38,6 +39,15 @@ public function testSkipInitializationForUnmappedProperties(): void
3839 self ::assertTrue ($ this ->dm ->isUninitializedObject ($ loadedDocument ));
3940 }
4041
42+ public function testSkipInitializationForStaticProperties (): void
43+ {
44+ $ loadedDocument = $ this ->dm ->getReference (DocumentWithStaticProperty::class, '123 ' );
45+ $ this ->assertInstanceOf (DocumentWithStaticProperty::class, $ loadedDocument );
46+
47+ self ::assertSame ('bar ' , $ loadedDocument ::$ foo );
48+ self ::assertTrue ($ this ->dm ->isUninitializedObject ($ loadedDocument ));
49+ }
50+
4151 public function testManyDeleteReference (): void
4252 {
4353 $ user = new User ();
Original file line number Diff line number Diff line change 1212use Doctrine \ODM \MongoDB \Proxy \InternalProxy ;
1313use Doctrine \ODM \MongoDB \Tests \BaseTestCase ;
1414use Documents \Cart ;
15+ use Documents \DocumentWithStaticProperty ;
1516use Documents \DocumentWithUnmappedProperties ;
1617use MongoDB \Client ;
1718use MongoDB \Collection ;
@@ -95,6 +96,23 @@ public function testCreateProxyForDocumentWithUnmappedProperties(): void
9596
9697 self ::assertSame ('bar ' , $ proxy ->foo );
9798 }
99+
100+ public function testCreateProxyForDocumentWithStaticProperties (): void
101+ {
102+ $ proxy = $ this ->dm ->getReference (DocumentWithStaticProperty::class, '123 ' );
103+ self ::assertTrue (self ::isLazyObject ($ proxy ));
104+
105+ // Disable initializer so we can access properties without initialising the object
106+ if ($ proxy instanceof InternalProxy) {
107+ $ proxy ->__setInitialized (true );
108+ } elseif ($ proxy instanceof GhostObjectInterface) {
109+ $ proxy ->setProxyInitializer (null );
110+ } elseif ($ this ->dm ->getConfiguration ()->isNativeLazyObjectEnabled ()) {
111+ $ this ->dm ->getClassMetadata ($ proxy ::class)->getReflectionClass ()->markLazyObjectAsInitialized ($ proxy );
112+ }
113+
114+ self ::assertSame ('bar ' , $ proxy ::$ foo );
115+ }
98116}
99117
100118class DocumentNotFoundListener
You can’t perform that action at this time.
0 commit comments