Example #1
0
 function teardown()
 {
     global $conf;
     // restore purge
     if (is_null($this->purge)) {
         unset($_REQUEST['purge']);
     } else {
         $_REQUEST['purge'] = $this->purge;
     }
     // restore $conf['cachedir'] if necessary
     if (!$this->cachedir) {
         unset($conf['cachedir']);
     }
     // restore io_functions
     runkit_function_rename('io_makefiledir', 'xhtml_htmlphp_test_io_makefiledir');
     if (function_exists('io_makefiledir_real')) {
         runkit_function_rename('io_makefiledir_real', 'io_makefiledir');
     }
     runkit_function_rename('io_savefile', 'xhtml_htmlphp_test_io_savefile');
     if (function_exists('io_savefile_real')) {
         runkit_function_rename('io_savefile_real', 'io_savefile');
     }
     // restore GeSHi::parse_code
     runkit_method_remove('GeSHi', 'parse_code');
     runkit_method_rename('GeSHi', 'parse_code_real', 'parse_code');
     parent::setup();
 }
Example #2
0
 public static function aggregate($destClass, $sourceClass)
 {
     $destClass = strtolower($destClass);
     $sourceClass = strtolower($sourceClass);
     if (!isset(self::$mixins[$destClass]) || !in_array($sourceClass, self::$mixins[$destClass])) {
         if (!function_exists('runkit_method_copy')) {
             throw new Exception('Warning : runkit extension must be installed to support mixins features.');
         }
         $reflection = new ReflectionClass($sourceClass);
         $sourceMethods = $reflection->getMethods();
         $destReflection = new ReflectionClass($destClass);
         // à virer en 5.1
         $destMethods = array();
         foreach ($destReflection->getMethods() as $method) {
             $destMethods[] = $method->name;
         }
         foreach ($sourceMethods as $method) {
             //if ($destReflection->hasMethod($method->name)) pas avant PHP 5.1
             if (!in_array($method->name, $destMethods)) {
                 runkit_method_copy($destClass, $method->name, $sourceClass);
             } else {
                 runkit_method_remove($destClass, $method->name);
                 runkit_method_copy($destClass, $method->name, $sourceClass);
             }
         }
         self::$mixins[$destClass][] = $sourceClass;
     }
 }
Example #3
0
 /**
  * Reverse a previously applied mutation to the given file
  *
  * @param array $mutation
  */
 public function reverseMutation(array $mutation)
 {
     if (runkit_method_remove($mutation['class'], $mutation['method']) == false) {
         throw new \Exception('runkit_method_remove() failed attempting to remove ' . $mutation['class'] . '::' . $mutation['method']);
     }
     if (runkit_method_rename($mutation['class'], $mutation['method'] . $this->_methodPreserveCode, $mutation['method']) == false) {
         throw new \Exception('runkit_method_rename() failed renaming from ' . $mutation['class'] . '::' . $mutation['method'] . $this->_methodPreserveCode . ' to ' . $mutation['class'] . '::' . $mutation['method'] . ' (mutation reversal)');
     }
 }
Example #4
0
 public static function restoreMethod($className, $methodName)
 {
     yTest_debugCC("restoreMethod {$className}::{$methodName}");
     $res = runkit_method_remove($className, strtolower($methodName));
     yTest_assert($res);
     $res = runkit_method_rename($className, strtolower(self::getOriginalMethodName($methodName)), strtolower($methodName));
     yTest_assert($res);
     //var_dump(get_class_methods($className));
 }
 /**
  * Clean-up function.
  *
  * Removes mocked method and restores the original was there is any.
  * Also removes the reference to the object from self::$instances.
  */
 public function restore()
 {
     if ($this->active) {
         list($class, $method) = $this->getClassAndMethod();
         runkit_method_remove($class, $method);
         runkit_method_rename($class, $this->restore_name, $method);
         $this->active = false;
     }
     parent::restore();
 }
Example #6
0
 /**
  * Reverse a previously applied mutation to the given file
  *
  * @param MutantInterface $mutant
  *
  * @throws \Exception
  */
 public function reverseMutation(MutantInterface $mutant)
 {
     $class = $mutant->getClassName();
     $method = $mutant->getMethodName();
     if (runkit_method_remove($class, $method) == false) {
         throw new \Exception('runkit_method_remove() failed attempting to remove ' . $class . '::' . $method);
     }
     if (runkit_method_rename($class, $method . $this->_methodPreserveCode, $method) == false) {
         throw new \Exception('runkit_method_rename() failed renaming from ' . $class . '::' . $method . $this->_methodPreserveCode . ' to ' . $class . '::' . $method . ' (mutation reversal)');
     }
 }
Example #7
0
 /**
  * Restore
  *
  * @return \MockFunction
  */
 public function restore()
 {
     if (!$this->_mock) {
         return $this;
     }
     $this->_mock = false;
     foreach ($this->_methods as $method) {
         runkit_method_remove($this->_class_name, $method);
         runkit_method_rename($this->_class_name, "_origin_" . $method, $method);
     }
     return $this;
 }
 protected function updateState($type, $id, $state)
 {
     $parts = explode('|', $id);
     switch ($type) {
         case self::STATIC_METHOD:
         case self::DYNAMIC_METHOD:
             $className = $parts[1];
             $methodName = $parts[2];
             $savedName = self::SAVED_PREFIX . $methodName;
             if ($state) {
                 // enable
                 is_callable("{$className}::{$methodName}");
                 $flags = RUNKIT_ACC_PUBLIC | ($type == self::STATIC_METHOD ? RUNKIT_ACC_STATIC : 0);
                 runkit_method_rename($className, $methodName, $savedName);
                 // save the original method
                 runkit_method_add($className, $methodName, '', $this->getExecuteCallCode($type, $id, $type === self::DYNAMIC_METHOD), $flags);
             } else {
                 // diable
                 runkit_method_remove($className, $methodName);
                 // remove the redefined instance
                 runkit_method_rename($className, $savedName, $methodName);
                 // restore the original
             }
             break;
         case self::GLOBAL_FUNCTION:
             $functionName = $parts[1];
             list($namespace, $baseName) = self::parseGlobalFunctionName($functionName);
             $functionName = $namespace . $baseName;
             $savedName = $namespace . self::SAVED_PREFIX . $baseName;
             if ($state) {
                 // enable
                 $tempName = "WikiaMockProxyTempFuncName";
                 // workaround for namespaces functions
                 runkit_function_rename($functionName, $savedName);
                 runkit_function_add($tempName, '', $this->getExecuteCallCode($type, $id));
                 runkit_function_rename($tempName, $functionName);
             } else {
                 // disable
                 runkit_function_remove($functionName);
                 // remove the redefined instance
                 runkit_function_rename($savedName, $functionName);
                 // restore the original
             }
             break;
     }
 }
Example #9
0
 /**
  * @param string $class
  * @param string $method
  *
  * @return boolean
  */
 public function removeMethod($class, $method)
 {
     if (!function_exists('runkit_method_remove')) {
         return false;
     }
     return runkit_method_remove($class, $method);
 }
Example #10
0
 protected function _reverseMethodCallRedirection()
 {
     $newOrigFuncName = $this->_functionName . $this->_origFuncSuffix;
     $spyFuncName = $this->_functionName . $this->_spyFuncSuffix;
     $isStatic = (new \ReflectionMethod($this->_context, $this->_functionName))->isStatic();
     if ($isStatic) {
         $origCallback = 'array("' . $this->_context . '", "' . $newOrigFuncName . '")';
     } else {
         $origCallback = 'array($this, "' . $newOrigFuncName . '")';
     }
     runkit_method_remove($this->_context, $spyFuncName);
     //keep memory address of function to prevent seg fault
     runkit_method_redefine($this->_context, $this->_functionName, '', '$args = func_get_args();
         return call_user_func_array(' . $origCallback . ', $args);', RUNKIT_ACC_PUBLIC | ($isStatic ? RUNKIT_ACC_STATIC : 0));
 }
 /**
  *
  * Remove the information about the pseudo implementation of the method
  *
  * @param string $method_name
  * @return $this
  */
 public function removeMethod($method_name)
 {
     if ($this->stashedMethodExists($method_name)) {
         runkit_method_remove($this->class_name, $method_name);
         runkit_method_rename($this->class_name, $this->getStashedMethodName($method_name), $method_name);
     }
     unset($this->methods[$method_name]);
     return $this;
 }
 public function undo()
 {
     runkit_method_remove($this->className, $this->delegateName);
 }
 public function undo()
 {
     runkit_method_remove($this->className, $this->getterName);
     runkit_method_remove($this->className, $this->setterName);
 }
Example #14
0
 /**
  * Revert redefined constructor
  *
  * @param string $class
  */
 public function revertRedefinedConstructor($class)
 {
     $this->loadClass($class);
     $backupMethod = $this->getBackupName(self::CONSTRUCTOR);
     try {
         $this->checkMethodDefined($class, $backupMethod);
     } catch (PStub_RunkitAdapter_Exception $e) {
         throw new PStub_RunkitAdapter_Exception('Constructor of the class ' . $class . ' was never redefined');
     }
     $tempMethod = $this->getTempName(self::CONSTRUCTOR);
     runkit_method_rename($class, self::CONSTRUCTOR, $tempMethod);
     runkit_method_rename($class, $backupMethod, self::CONSTRUCTOR);
     runkit_method_remove($class, $tempMethod);
 }
Example #15
0
 /**
  * Unmock a method.
  *
  * @param Callable $method Method defined in an array form
  *
  * @return void
  */
 protected function unmock_method($method)
 {
     $class_name = is_object($method[0]) ? get_class($method[0]) : $method[0];
     $method_name = $method[1];
     runkit_method_remove($class_name, $method_name);
     runkit_method_rename($class_name, $method_name . self::FUNCTION_ID, $method_name);
 }
Example #16
0
 /**
  *	Reset original definition.
  */
 public static function resetMethod($class, $method)
 {
     $originalMethod = "__original_{$method}";
     if (method_exists($class, $originalMethod)) {
         runkit_method_remove($class, $method);
         runkit_method_rename($class, $originalMethod, $method);
     }
 }