Skip to content

Commit 23af31f

Browse files
1 parent 7fe4bbd commit 23af31f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Restorer.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,41 @@ public function restoreGlobalVariables(Snapshot $snapshot)
7272
*/
7373
public function restoreStaticAttributes(Snapshot $snapshot)
7474
{
75+
$current = new Snapshot($snapshot->blacklist(), false, false, false, false, true, false, false, false, false);
76+
$newClasses = array_diff($current->classes(), $snapshot->classes());
77+
unset($current);
78+
7579
foreach ($snapshot->staticAttributes() as $className => $staticAttributes) {
7680
foreach ($staticAttributes as $name => $value) {
7781
$reflector = new ReflectionProperty($className, $name);
7882
$reflector->setAccessible(true);
7983
$reflector->setValue($value);
8084
}
8185
}
86+
87+
foreach ($newClasses as $className) {
88+
$class = new \ReflectionClass($className);
89+
$defaults = $class->getDefaultProperties();
90+
91+
foreach ($class->getProperties() as $attribute) {
92+
if (!$attribute->isStatic()) {
93+
continue;
94+
}
95+
96+
$name = $attribute->getName();
97+
98+
if ($snapshot->blacklist()->isStaticAttributeBlacklisted($className, $name)) {
99+
continue;
100+
}
101+
102+
if (!isset($defaults[$name])) {
103+
continue;
104+
}
105+
106+
$attribute->setAccessible(true);
107+
$attribute->setValue($defaults[$name]);
108+
}
109+
}
82110
}
83111

84112
/**

0 commit comments

Comments
 (0)