/** * Creates a snapshot of all static attributes in user-defined classes. */ private function snapshotStaticAttributes() { foreach ($this->classes as $className) { $class = new ReflectionClass($className); $snapshot = array(); foreach ($class->getProperties() as $attribute) { if ($attribute->isStatic()) { $name = $attribute->getName(); if ($this->blacklist->isStaticAttributeBlacklisted($className, $name)) { continue; } $attribute->setAccessible(true); $value = $attribute->getValue(); if ($this->canBeSerialized($value)) { $snapshot[$name] = unserialize(serialize($value)); } } } if (!empty($snapshot)) { $this->staticAttributes[$className] = $snapshot; } } }
public function testStaticAttributeCanBeBlacklisted() { $this->blacklist->addStaticAttribute('SebastianBergmann\\GlobalState\\TestFixture\\BlacklistedClass', 'attribute'); $this->assertTrue($this->blacklist->isStaticAttributeBlacklisted('SebastianBergmann\\GlobalState\\TestFixture\\BlacklistedClass', 'attribute')); }