Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Badoo/SoftMocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ class SoftMocks
{
const MOCKS_CACHE_TOUCHTIME = 86400; // 1 day

const LOCK_FILE_PATH_NAME = 'soft_mocks_rewrite.lock';

private static $rewrite_cache = [/* source => target */];
private static $orig_paths = [/* target => source */];

Expand Down Expand Up @@ -469,7 +471,7 @@ class SoftMocks
];
private static $base_paths = [];
private static $prepare_for_rewrite_callback;
private static $lock_file_path = '/tmp/mocks/soft_mocks_rewrite.lock';
private static $lock_file_path;

protected static function getEnvironment($key)
{
Expand All @@ -489,6 +491,7 @@ public static function init()
}
self::setMocksCachePath($mocks_cache_path);
}
self::setLockFilePath(rtrim(self::$mocks_cache_path . '/', '/') . self::LOCK_FILE_PATH_NAME);
// todo constant will be removed in next major release, because it's like project path.
if (!defined('SOFTMOCKS_ROOT_PATH')) {
/**
Expand Down Expand Up @@ -726,13 +729,17 @@ public static function setRewriteInternal($rewrite_internal)
*/
public static function setMocksCachePath($mocks_cache_path)
{
$dir_path = $mocks_cache_path;
if (!empty($mocks_cache_path)) {
self::$mocks_cache_path = rtrim($mocks_cache_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$dir_path = rtrim($mocks_cache_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}

if (!is_dir(self::$mocks_cache_path) && !mkdir(self::$mocks_cache_path, 0777) && !is_dir(self::$mocks_cache_path)) {
throw new \RuntimeException("Can't create cache dir for rewritten files at " . self::$mocks_cache_path);

if (!is_dir($dir_path) && !mkdir($dir_path, 0777) && !is_dir($dir_path)) {
throw new \RuntimeException("Can't create cache dir for rewritten files at " . $dir_path);
}

self::$mocks_cache_path = realpath($dir_path) ?: $dir_path;
}

/**
Expand Down