2
2
3
3
namespace PhpArsenal \SymfonyMongoTestingFoundation \SnapshotDriver ;
4
4
5
+ use App \General \Doctrine \AbstractDocument ;
5
6
use PHPUnit \Framework \Assert ;
7
+ use ProxyManager \Configuration ;
8
+ use ProxyManager \Inflector \ClassNameInflector ;
6
9
use Spatie \Snapshots \Driver ;
7
10
use Symfony \Component \Serializer \Encoder \JsonEncoder ;
8
11
use Symfony \Component \Serializer \Normalizer \AbstractNormalizer ;
14
17
15
18
class SnapshotJsonObjectDriver implements Driver
16
19
{
20
+ private static ?ClassNameInflector $ classNameInflector = null ;
21
+
17
22
public function __construct (
18
23
private array $ ignoredProperties = [],
19
24
private array $ redactedProperties = []
@@ -32,12 +37,12 @@ public function serialize($data): string
32
37
33
38
$ normalizedData = $ serializer ->normalize ($ data , 'array ' , [
34
39
AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => function ($ object , $ format , $ context ) {
35
- return sprintf ('CIRCULAR_%s ' , array_reverse (explode ('\\' , get_class ($ object )))[0 ]);
40
+ return sprintf ('CIRCULAR_%s ' , array_reverse (explode ('\\' , self :: resolveFromObject ($ object )))[0 ]);
36
41
},
37
42
AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true ,
38
43
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true ,
39
44
AbstractObjectNormalizer::MAX_DEPTH_HANDLER => function ($ innerObject , $ outerObject , string $ attributeName , string $ format = null , array $ context = []) {
40
- return sprintf ('MAX_DEPTH_%s ' , array_reverse (explode ('\\' , get_class ( $ object )))[0 ]);
45
+ return sprintf ('MAX_DEPTH_%s ' , array_reverse (explode ('\\' , self :: resolveFromObject ( $ innerObject )))[0 ]);
41
46
},
42
47
AbstractNormalizer::IGNORED_ATTRIBUTES => $ this ->ignoredProperties ,
43
48
]);
@@ -85,4 +90,23 @@ private function redactKeys(array &$values, array $redactedKeys): void
85
90
}
86
91
}
87
92
}
93
+
94
+ private static function resolve (string $ proxyObjectClass ): string
95
+ {
96
+ return self ::getClassNameInflector ()->getUserClassName ($ proxyObjectClass );
97
+ }
98
+
99
+ private static function resolveFromObject (object $ object ): string
100
+ {
101
+ return self ::resolve ($ object ::class);
102
+ }
103
+
104
+ private static function getClassNameInflector (): ClassNameInflector
105
+ {
106
+ if (!self ::$ classNameInflector ) {
107
+ self ::$ classNameInflector = (new Configuration ())->getClassNameInflector ();
108
+ }
109
+
110
+ return self ::$ classNameInflector ;
111
+ }
88
112
}
0 commit comments