Skip to content

Commit 4ccb510

Browse files
committed
Fix path resolution for dir when PrivateTmp=on
1 parent 717adcb commit 4ccb510

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Badoo/SoftMocks.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 @@ public static function init()
489491
}
490492
self::setMocksCachePath($mocks_cache_path);
491493
}
494+
self::setLockFilePath(rtrim(self::$mocks_cache_path . '/', '/') . self::LOCK_FILE_PATH_NAME);
492495
// todo constant will be removed in next major release, because it's like project path.
493496
if (!defined('SOFTMOCKS_ROOT_PATH')) {
494497
/**
@@ -726,13 +729,17 @@ public static function setRewriteInternal($rewrite_internal)
726729
*/
727730
public static function setMocksCachePath($mocks_cache_path)
728731
{
732+
$dir_path = $mocks_cache_path;
729733
if (!empty($mocks_cache_path)) {
730-
self::$mocks_cache_path = rtrim($mocks_cache_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
734+
$dir_path = rtrim($mocks_cache_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
731735
}
732736

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);
737+
738+
if (!is_dir($dir_path) && !mkdir($dir_path, 0777) && !is_dir($dir_path)) {
739+
throw new \RuntimeException("Can't create cache dir for rewritten files at " . $dir_path);
735740
}
741+
742+
self::$mocks_cache_path = realpath($dir_path) ?: $dir_path;
736743
}
737744

738745
/**

0 commit comments

Comments
 (0)