Example #1
0
function plugin_wix_init()
{
    define('PatternFile', dirname(__FILE__) . '/WixPattern.txt');
    require_once $_SERVER['DOCUMENT_ROOT'] . '/wix_cms_newbody.php';
    runkit_function_rename('catbody', 'old_catbody');
    runkit_function_rename('new_catbody', 'catbody');
}
 function teardown()
 {
     runkit_function_rename('unslash', 'html_hilight_test_unslash');
     if (function_exists('html_hilight_test_unslash_real')) {
         runkit_function_rename('html_hilight_test_unslash_real', 'unslash');
     }
 }
Example #3
0
 public function getMock()
 {
     $mock = $this->testCase->getMock('stdClass', $this->functions, array(), 'PHPUnit_Extension_FunctionMocker_' . uniqid());
     foreach ($this->functions as $function) {
         $fqFunction = $this->namespace . '\\' . $function;
         if (in_array($fqFunction, static::$mockedFunctions, true)) {
             continue;
         }
         if (!extension_loaded('runkit') || !ini_get('runkit.internal_override')) {
             PHPUnit_Extension_FunctionMocker_CodeGenerator::defineFunction($function, $this->namespace);
         } elseif (!function_exists('__phpunit_function_mocker_' . $function)) {
             runkit_function_rename($function, '__phpunit_function_mocker_' . $function);
             error_log($function);
             runkit_method_redefine($function, function () use($function) {
                 if (!isset($GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'][$this->namespace])) {
                     return call_user_func_array('__phpunit_function_mocker_' . $function, func_get_args());
                 }
                 return call_user_func_array(array($GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'][$this->namespace], $function), func_get_args());
             });
             var_dump(strlen("foo"));
         }
         static::$mockedFunctions[] = $fqFunction;
     }
     if (!isset($GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'])) {
         $GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'] = array();
     }
     $GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'][$this->namespace] = $mock;
     return $mock;
 }
Example #4
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 #5
0
 /**
  *	Reset original function.
  */
 public static function resetFunction($function)
 {
     $originalFunction = "__original_{$function}";
     if (function_exists($originalFunction)) {
         runkit_function_remove($function);
         runkit_function_rename($originalFunction, $function);
     }
 }
 /**
  * Disable
  *
  * @return \MockFunction
  */
 public function disable()
 {
     if ($this->active) {
         $this->active = false;
         runkit_function_remove($this->functionName);
         runkit_function_rename($this->functionAlias, $this->functionName);
     }
     return $this;
 }
Example #7
0
 /**
  * Restore
  *
  * @return \MockFunction
  */
 public function restore()
 {
     if (!$this->_mock) {
         return $this;
     }
     $this->_mock = false;
     runkit_function_remove($this->_function_name);
     runkit_function_rename($this->_function_alias, $this->_function_name);
     return $this;
 }
 public static function tearDownAfterClass()
 {
     if (self::$skipped) {
         return;
     }
     runkit_function_rename('pinba_timer_start', 'pinba_timer_start_callback');
     runkit_function_rename('pinba_timer_stop', 'pinba_timer_stop_callback');
     runkit_function_rename('pinba_timer_start_bak', 'pinba_timer_start');
     runkit_function_rename('pinba_timer_stop_bak', 'pinba_timer_stop');
 }
Example #9
0
 public function tearDown()
 {
     if (function_exists('TEST_SAVED_file_get_contents')) {
         runkit_function_remove('file_get_contents');
         runkit_function_rename('TEST_SAVED_file_get_contents', 'file_get_contents');
     }
     if (function_exists('TEST_SAVED_stream_context_create')) {
         runkit_function_remove('stream_context_create');
         runkit_function_rename('TEST_SAVED_stream_context_create', 'stream_context_create');
     }
     self::$fgcReturn = '{}';
 }
 /**
  * @BeforeSuite
  */
 public static function blackMagicBeforeSuite(SuiteEvent $event)
 {
     $parameters = $event->getContextParameters();
     if (false === isset($parameters['customDate'])) {
         throw new \Exception("You don't have customDate in your behat parameters\n");
     }
     global $custom_date;
     self::$_date = $custom_date = $parameters['customDate'];
     $rename = function ($real_name, $fake_name) {
         runkit_function_rename($real_name, "real_{$real_name}");
         runkit_function_rename("ETNA\\FeatureContext\\{$fake_name}", $real_name);
     };
     $rename("time", "fakeTime");
     $rename("date", "fakeDate");
     $rename("strtotime", "fakeStrtotime");
 }
Example #11
0
 /**
  * @param string $f
  */
 protected function override($f)
 {
     runkit_function_rename($f, $f . '_native');
     runkit_function_rename('PHPDaemon\\Thread\\' . $f, $f);
 }
Example #12
0
        runkit_function_add("time", "", <<<FUNC
\t        return original_time() + \$_ENV["{$travelName}"];
FUNC
);
        // replace strtotime()
        runkit_function_rename("strtotime", "original_strtotime");
        runkit_function_add("strtotime", '$time, $now = 0', <<<'FUNC'
	        if (isset($now)
	                && !empty($now))
	            return original_strtotime($time, $now);
	        else
	            return original_strtotime($time, time());
FUNC
);
        // replace date()
        runkit_function_rename("date", "original_date");
        runkit_function_add("date", '$format, $timestamp = 0', <<<'FUNC'
	        if (isset($timestamp)
	                && !empty($timestamp))
	            return original_date($format, $timestamp);
	        else
	            return original_date($format, time());
FUNC
);
        return true;
    };
    if (extension_loaded("uopz")) {
        ini_set("uopz.overloads", 1);
        return $travelByUopz;
    } else {
        if (extension_loaded("runkit")) {
Example #13
0
 /**
  * Revert redefenition of the function
  *
  * @param string $function
  */
 public function revertRedefinedFunction($function)
 {
     $this->checkFunctionExists($function);
     $backupFunction = $this->getBackupName($function);
     try {
         $this->checkFunctionExists($backupFunction);
     } catch (PStub_RunkitAdapter_Exception $e) {
         throw new PStub_RunkitAdapter_Exception('Function ' . $function . ' was never redefined');
     }
     runkit_function_remove($function);
     runkit_function_rename($backupFunction, $function);
 }
Example #14
0
 /**
  *    Removes the mock function implementation and restores
  *    the previously declared implementation
  *    @access public
  */
 function restore()
 {
     runkit_function_remove($this->_function) or trigger_error('Error removing mock function', E_USER_ERROR);
     runkit_function_rename($this->_tmp_function, $this->_function) or trigger_error('Error restoring real function', E_USER_ERROR);
 }
Example #15
0
 /**
  * Override a standard PHP function
  * @param string $local e.g. isUploadedFile
  * @param string $real e.g. is_uploaded_file
  */
 protected function override($camelCase, $real)
 {
     runkit_function_rename($real, $real . '_native');
     runkit_function_rename('PHPDaemon\\Thread\\' . $camelCase, $real);
 }
Example #16
0
 /**
  * Overrides native PHP functions.
  * @return void
  */
 public function overrideNativeFuncs()
 {
     if (Daemon::supported(Daemon::SUPPORT_RUNKIT_INTERNAL_MODIFY)) {
         runkit_function_rename('header', 'header_native');
         function header()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'header'), func_get_args());
             }
         }
         runkit_function_rename('is_uploaded_file', 'is_uploaded_file_native');
         function is_uploaded_file()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'isUploadedFile'), func_get_args());
             }
         }
         runkit_function_rename('move_uploaded_file', 'move_uploaded_file_native');
         function move_uploaded_file()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'moveUploadedFile'), func_get_args());
             }
         }
         runkit_function_rename('headers_sent', 'headers_sent_native');
         function headers_sent()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return Daemon::$req->headers_sent();
             }
         }
         runkit_function_rename('headers_list', 'headers_list_native');
         function headers_list()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return Daemon::$req->headers_list();
             }
         }
         runkit_function_rename('setcookie', 'setcookie_native');
         function setcookie()
         {
             if (Daemon::$req && Daemon::$req instanceof HTTPRequest) {
                 return call_user_func_array(array(Daemon::$req, 'setcookie'), func_get_args());
             }
         }
         register_shutdown_function(array($this, 'shutdown'));
         runkit_function_rename('register_shutdown_function', 'register_shutdown_function_native');
         function register_shutdown_function($cb)
         {
             if (Daemon::$req) {
                 return Daemon::$req->registerShutdownFunction($cb);
             }
         }
         runkit_function_copy('create_function', 'create_function_native');
         runkit_function_redefine('create_function', '$arg,$body', 'return __create_function($arg,$body);');
         function __create_function($arg, $body)
         {
             static $cache = array();
             static $maxCacheSize = 64;
             static $sorter;
             if ($sorter === NULL) {
                 $sorter = function ($a, $b) {
                     if ($a->hits == $b->hits) {
                         return 0;
                     }
                     return $a->hits < $b->hits ? 1 : -1;
                 };
             }
             $crc = crc32($arg . "" . $body);
             if (isset($cache[$crc])) {
                 ++$cache[$crc][1];
                 return $cache[$crc][0];
             }
             if (sizeof($cache) >= $maxCacheSize) {
                 uasort($cache, $sorter);
                 array_pop($cache);
             }
             $cache[$crc] = array($cb = eval('return function(' . $arg . '){' . $body . '};'), 0);
             return $cb;
         }
     }
 }
Example #17
0
 /**
  * @param string $oldName
  * @param string $newName
  *
  * @return boolean
  */
 public function renameFunction($oldName, $newName)
 {
     if (!function_exists('runkit_function_rename')) {
         return false;
     }
     return runkit_function_rename($oldName, $newName);
 }
Example #18
0
            }
        }
        if (count($attrs) == $found) {
            $results[] = $subarray;
        }
        $found = 0;
    }
    return $results;
}
/*
 * Product Filter Get Variable Product
*/
$curr_variable = get_option('wc_settings_prdctfltr_use_variable_images', 'no');
if ($curr_variable == 'yes') {
    if (function_exists('runkit_function_rename') && function_exists('woocommerce_get_product_thumbnail')) {
        runkit_function_rename('woocommerce_get_product_thumbnail', 'old_woocommerce_get_product_thumbnail');
    }
    if (!function_exists('woocommerce_get_product_thumbnail')) {
        function woocommerce_get_product_thumbnail($size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0)
        {
            $product = get_product(get_the_ID());
            $attrs = array();
            foreach ($_GET as $k => $v) {
                if (substr($k, 0, 3) == 'pa_') {
                    if (!strpos($v, ',')) {
                        $v_val = $v;
                    } else {
                        $v_val = explode(',', $v);
                        $v_val = $v_val[0];
                    }
                    $attrs = $attrs + array($k => $v_val);
Example #19
0
 /**
  * Unmock a PHP function.
  *
  * @param String $name Function name
  *
  * @return void
  */
 protected function unmock_function($name)
 {
     runkit_function_remove($name);
     runkit_function_rename($name . self::FUNCTION_ID, $name);
 }
Example #20
0
 /**
  * Perform actual function renaming.
  *
  * It actually swaps the two functions with each other, which is why
  * there are three calls to rename the function.
  *
  * @param string $originalName
  * @param string $replacement
  */
 protected function doFunctionRename($originalName, $replacement)
 {
     if (!extension_loaded('test_helpers') && !extension_loaded('runkit')) {
         die('test_helpers extension and runkit extensions are not found - you need one of them');
     }
     $this->confirmFunction($originalName);
     $this->confirmFunction($replacement);
     $tempName = $originalName . '_TEMP';
     while (function_exists($tempName)) {
         $tempName .= substr(uniqid(), -4);
     }
     // Runkit's function renaming works better in PHP 5.4
     if (function_exists('runkit_function_rename')) {
         runkit_function_rename($originalName, $tempName);
         runkit_function_rename($replacement, $originalName);
         runkit_function_rename($tempName, $replacement);
     } else {
         rename_function($originalName, $tempName);
         rename_function($replacement, $originalName);
         rename_function($tempName, $replacement);
     }
 }
 /**
  * Restore the original function
  */
 public function reset()
 {
     runkit_function_remove($this->funcName);
     runkit_function_rename($this->tmpFuncName, $this->funcName);
     MockFunctionContainer::unregister($this->funcName);
 }
Example #22
0
/**
 * Restores date function
 *
 * @return void
 */
function tearDownForTestsUsingDate()
{
    if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) {
        runkit_function_rename('date', 'test_date');
        runkit_function_rename('test_date_override', 'date');
    }
}
 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 #24
0
 /**
  * Clean-up function.
  *
  * Removes mocked function and restored the original was there is any.
  * Also removes the reference to the object from self::$instances.
  */
 public function restore()
 {
     if ($this->active) {
         runkit_function_remove($this->function_name);
         if (isset($this->restore_name)) {
             runkit_function_rename($this->restore_name, $this->function_name);
         }
         $this->active = false;
     }
     if (isset(self::$instances[$this->id])) {
         unset(self::$instances[$this->id]);
     }
 }