コード例 #1
0
 public function test_patch_miss_cache()
 {
     $cache_dir = APPPATH . 'tests/_ci_phpunit_test/tmp/cache_test';
     CIPHPUnitTest::setPatcherCacheDir($cache_dir);
     $cache_file = Cache::getSrcCacheFilePath(__FILE__);
     $this->assertFalse(file_exists($cache_file));
     MonkeyPatchManager::patch(__FILE__);
     $this->assertTrue(file_exists($cache_file));
 }
コード例 #2
0
ファイル: Proxy.php プロジェクト: yutayokoi/CodeIgniter
 protected static function checkPassedByReference($function)
 {
     $ref_func = new ReflectionFunction($function);
     foreach ($ref_func->getParameters() as $param) {
         if ($param->isPassedByReference()) {
             // Add tmp blacklist
             Cache::appendTmpFunctionBlacklist($function);
             // Remove cache file
             $backtrace = debug_backtrace();
             $info = Backtrace::getInfo('FunctionPatcher', $backtrace);
             $orig_file = $info['file'];
             $cache = Cache::removeSrcCacheFile($orig_file);
             $pr_msg = '';
             if (self::isInternalFunction($function)) {
                 $pr_msg = "<red>Please send Pull Request to add function '{$function}' to default config.</red>\n";
             }
             $tmp_blacklist_file = Cache::getTmpFunctionBlacklistFile();
             $msg = "\n" . "<red>Can't patch on function '{$function}'.</red>\n" . "It has param(s) passed by reference.\n" . "Added it temporary blacklist file '{$tmp_blacklist_file}'.\n" . "And removed cache file '{$cache}'.\n" . "{$pr_msg}" . "\n<red>Please run phpunit again.</red>";
             self::outputMessage($msg);
             throw new LogicException($msg);
         }
     }
 }
コード例 #3
0
 /**
  * @param string $path original source file path
  * @return resource
  * @throws LogicException
  */
 public static function patch($path)
 {
     if (!is_readable($path)) {
         throw new LogicException("Can't read '{$path}'");
     }
     // Check cache file
     if ($cache_file = Cache::getValidSrcCachePath($path)) {
         self::log('cache_hit: ' . $path);
         return fopen($cache_file, 'r');
     }
     self::log('cache_miss: ' . $path);
     $source = file_get_contents($path);
     list($new_source, $patched) = self::execPatchers($source);
     // Write to cache file
     self::log('write_cache: ' . $path);
     Cache::writeSrcCacheFile($path, $new_source);
     $resource = fopen('php://memory', 'rb+');
     fwrite($resource, $new_source);
     rewind($resource);
     return $resource;
 }
コード例 #4
0
 public function test_clearCache()
 {
     Cache::clearCache();
     $this->assertFalse(file_exists(ReflectionHelper::getPrivateProperty(__NAMESPACE__ . '\\Cache', 'cache_dir')));
 }