/**
  * 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;
         }
     }
 }
示例#2
0
 /**
  * @param  boolean $backupGlobals
  * @return Snapshot
  */
 private function createGlobalStateSnapshot($backupGlobals)
 {
     $blacklist = new Blacklist();
     foreach ($this->backupGlobalsBlacklist as $globalVariable) {
         $blacklist->addGlobalVariable($globalVariable);
     }
     if (!defined('PHPUNIT_TESTSUITE')) {
         $blacklist->addClassNamePrefix('PHPUnit');
         $blacklist->addClassNamePrefix('File_Iterator');
         $blacklist->addClassNamePrefix('PHP_CodeCoverage');
         $blacklist->addClassNamePrefix('PHP_Invoker');
         $blacklist->addClassNamePrefix('PHP_Timer');
         $blacklist->addClassNamePrefix('PHP_Token');
         $blacklist->addClassNamePrefix('Symfony');
         $blacklist->addClassNamePrefix('Text_Template');
         $blacklist->addClassNamePrefix('Doctrine\\Instantiator');
         foreach ($this->backupStaticAttributesBlacklist as $class => $attributes) {
             foreach ($attributes as $attribute) {
                 $blacklist->addStaticAttribute($class, $attribute);
             }
         }
     }
     return new Snapshot($blacklist, $backupGlobals, $this->backupStaticAttributes, false, false, false, false, false, false, false);
 }
示例#3
0
 private function snapshotGlobalState()
 {
     if ($this->runTestInSeparateProcess || $this->inIsolation) {
         return;
     }
     $backupGlobals = $this->backupGlobals === null || $this->backupGlobals === true;
     if ($backupGlobals || $this->backupStaticAttributes) {
         $blacklist = new Blacklist();
         if ($backupGlobals) {
             foreach ($this->backupGlobalsBlacklist as $globalVariable) {
                 $blacklist->addGlobalVariable($globalVariable);
             }
         }
         if ($this->backupStaticAttributes && !defined('PHPUNIT_TESTSUITE')) {
             $blacklist->addClassNamePrefix('PHPUnit');
             $blacklist->addClassNamePrefix('File_Iterator');
             $blacklist->addClassNamePrefix('PHP_CodeCoverage');
             $blacklist->addClassNamePrefix('PHP_Invoker');
             $blacklist->addClassNamePrefix('PHP_Timer');
             $blacklist->addClassNamePrefix('PHP_Token');
             $blacklist->addClassNamePrefix('Symfony');
             $blacklist->addClassNamePrefix('Text_Template');
             $blacklist->addClassNamePrefix('Doctrine\\Instantiator');
             foreach ($this->backupStaticAttributesBlacklist as $class => $attributes) {
                 foreach ($attributes as $attribute) {
                     $blacklist->addStaticAttribute($class, $attribute);
                 }
             }
         }
         $this->snapshot = new Snapshot($blacklist, $backupGlobals, $this->backupStaticAttributes, false, false, false, false, false, false, false);
     }
 }
示例#4
0
 public function testStaticAttributeCanBeBlacklisted()
 {
     $this->blacklist->addStaticAttribute('SebastianBergmann\\GlobalState\\TestFixture\\BlacklistedClass', 'attribute');
     $this->assertTrue($this->blacklist->isStaticAttributeBlacklisted('SebastianBergmann\\GlobalState\\TestFixture\\BlacklistedClass', 'attribute'));
 }