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));
 }
 /**
  * @param string $path original source file path
  * @return resource
  * @throws LogicException
  */
 public static function patch($path)
 {
     if (Cache::getCacheDir() === null) {
         throw new LogicException("You have to set 'cache_dir'");
     }
     if (!is_readable($path)) {
         throw new LogicException("Can't read '{$path}'");
     }
     // Check cache file
     if (Cache::hasValidSrcCache($path)) {
         self::log('cache_hit: ' . $path);
         return fopen(Cache::getSrcCacheFilePath($path), '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;
 }