File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -110,9 +110,21 @@ public function __get(string $property) : mixed
110
110
throw $ this ->propertyNotDefined ($ property );
111
111
}
112
112
113
+ /**
114
+ * Converts the entity to a JSON string.
115
+ * All properties will be included.
116
+ * Please note that sensitive property data may be exposed!
117
+ *
118
+ * @return string
119
+ */
113
120
public function __toString () : string
114
121
{
115
- return \json_encode ($ this , $ this ->_jsonFlags ); // @phpstan-ignore-line
122
+ $ origin = $ this ->_jsonVars ;
123
+ $ all = \array_keys ($ this ->getObjectVars ());
124
+ $ this ->_jsonVars = $ all ;
125
+ $ json = \json_encode ($ this , $ this ->_jsonFlags );
126
+ $ this ->_jsonVars = $ origin ;
127
+ return $ json ; // @phpstan-ignore-line
116
128
}
117
129
118
130
protected function propertyNotDefined (string $ property ) : OutOfBoundsException
Original file line number Diff line number Diff line change @@ -183,8 +183,14 @@ public function testJsonVars() : void
183
183
184
184
public function testToString () : void
185
185
{
186
+ $ origin = $ this ->entity ->_jsonVars ;
186
187
$ json = (string ) $ this ->entity ;
188
+ self ::assertSame ($ origin , $ this ->entity ->_jsonVars );
187
189
self ::assertStringStartsWith ('{ ' , $ json );
188
- self ::assertStringEndsWith ('} ' , $ json );
190
+ $ values = \json_decode ($ json , true );
191
+ self ::assertArrayHasKey ('array ' , $ values );
192
+ self ::assertIsArray ($ values ['array ' ]);
193
+ self ::assertArrayHasKey ('id ' , $ values );
194
+ self ::assertNull ($ values ['id ' ]);
189
195
}
190
196
}
You can’t perform that action at this time.
0 commit comments