File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -86,4 +86,15 @@ private function cloneArray(array &$array)
8686 }
8787 }
8888 }
89+
90+ /**
91+ * Restore object from var_export
92+ *
93+ * @param array $values
94+ * @return DataObject
95+ */
96+ public static function __set_state (array $ values )
97+ {
98+ return new static ($ values );
99+ }
89100}
Original file line number Diff line number Diff line change @@ -137,4 +137,27 @@ public function testCloneAggregateInDeepArray()
137137 $ clone ->property [0 ][0 ]
138138 );
139139 }
140+
141+ public function testSetState ()
142+ {
143+ $ struct = new TestDataObject ();
144+ $ struct ->property = 42 ;
145+
146+ $ restored = eval ("return " . var_export ($ struct , true ) . '; ' );
147+
148+ $ this ->assertEquals ($ struct , $ restored );
149+ $ this ->assertNotSame ($ struct , $ restored );
150+ }
151+
152+ /**
153+ * @expectedException \OutOfRangeException
154+ */
155+ public function testFailOnInvalidSetState ()
156+ {
157+ TestDataObject::__set_state (
158+ array (
159+ 'invalid ' => 42 ,
160+ )
161+ );
162+ }
140163}
You can’t perform that action at this time.
0 commit comments