@@ -414,6 +414,8 @@ class SoftMocks
414414{
415415 const MOCKS_CACHE_TOUCHTIME = 86400 ; // 1 day
416416
417+ const LOCK_FILE_PATH_NAME = 'soft_mocks_rewrite.lock ' ;
418+
417419 private static $ rewrite_cache = [/* source => target */ ];
418420 private static $ orig_paths = [/* target => source */ ];
419421
@@ -469,7 +471,7 @@ class SoftMocks
469471 ];
470472 private static $ base_paths = [];
471473 private static $ prepare_for_rewrite_callback ;
472- private static $ lock_file_path = ' /tmp/mocks/soft_mocks_rewrite.lock ' ;
474+ private static $ lock_file_path ;
473475
474476 protected static function getEnvironment ($ key )
475477 {
@@ -489,6 +491,9 @@ public static function init()
489491 }
490492 self ::setMocksCachePath ($ mocks_cache_path );
491493 }
494+ if (!self ::$ lock_file_path ) {
495+ self ::$ lock_file_path = self ::$ mocks_cache_path . '/ ' . LOCK_FILE_PATH_NAME ;
496+ }
492497 // todo constant will be removed in next major release, because it's like project path.
493498 if (!defined ('SOFTMOCKS_ROOT_PATH ' )) {
494499 /**
@@ -726,13 +731,17 @@ public static function setRewriteInternal($rewrite_internal)
726731 */
727732 public static function setMocksCachePath ($ mocks_cache_path )
728733 {
734+ $ dir_path = $ mocks_cache_path ;
729735 if (!empty ($ mocks_cache_path )) {
730- self :: $ mocks_cache_path = rtrim ($ mocks_cache_path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ;
736+ $ dir_path = rtrim ($ mocks_cache_path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ;
731737 }
732738
733- if (!is_dir (self ::$ mocks_cache_path ) && !mkdir (self ::$ mocks_cache_path , 0777 ) && !is_dir (self ::$ mocks_cache_path )) {
734- throw new \RuntimeException ("Can't create cache dir for rewritten files at " . self ::$ mocks_cache_path );
739+
740+ if (!is_dir ($ dir_path ) && !mkdir ($ dir_path , 0777 ) && !is_dir ($ dir_path )) {
741+ throw new \RuntimeException ("Can't create cache dir for rewritten files at " . $ dir_path );
735742 }
743+
744+ self ::$ mocks_cache_path = realpath ($ dir_path ) ?: $ dir_path ;
736745 }
737746
738747 /**
0 commit comments