Skip to content

Commit ab0abe6

Browse files
committed
Environment: improvements
1 parent 533b1ec commit ab0abe6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/Environment.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Nette\Caching\Storages\FileStorage;
66
use Nette\Loaders\RobotLoader;
7+
use RuntimeException;
78
use Tester\Environment as TEnvironment;
89
use Tester\Helpers as THelpers;
910

@@ -67,8 +68,6 @@ public static function setupTimezone($timezone = 'Europe/Prague')
6768
*/
6869
public static function setupVariables($testerDir)
6970
{
70-
clearstatcache();
71-
7271
if (!is_dir($testerDir)) {
7372
die(sprintf('Provide existing folder, "%s" does not exist.', $testerDir));
7473
}
@@ -93,8 +92,13 @@ public static function setupVariables($testerDir)
9392
ini_set('session.save_path', TEMP_DIR);
9493

9594
// Create folders
96-
self::mkdir(TEMP_DIR);
95+
clearstatcache(TRUE, TMP_DIR);
96+
self::mkdir(TMP_DIR);
97+
clearstatcache(TRUE, CACHE_DIR);
9798
self::mkdir(CACHE_DIR);
99+
clearstatcache(TRUE, TEMP_DIR);
100+
self::mkdir(TEMP_DIR);
101+
clearstatcache(TRUE, TEMP_DIR);
98102
self::purge(TEMP_DIR);
99103
}
100104

@@ -154,16 +158,16 @@ public static function setupRobotLoader(callable $callback = NULL)
154158

155159
/**
156160
* @param string $dir
157-
* @param int $mask
161+
* @param int $mode
158162
* @param bool $recursive
159163
* @return void
160164
*/
161165
public static function mkdir($dir, $mode = 0777, $recursive = TRUE)
162166
{
163-
clearstatcache();
164-
if (!is_dir($dir) && !@mkdir($dir, $mode, $recursive)) { // @ - dir may already exist
167+
if (is_dir($dir) === FALSE && @mkdir($dir, $mode, $recursive) === FALSE) {
168+
clearstatcache(TRUE, $dir);
165169
$error = error_get_last();
166-
if (!is_dir($dir)) {
170+
if (is_dir($dir) === FALSE && !file_exists($dir) === FALSE) {
167171
throw new RuntimeException("Unable to create directory '$dir'. " . $error['message']);
168172
}
169173
}
@@ -186,9 +190,7 @@ public static function rmdir($dir)
186190
*/
187191
private static function purge($dir)
188192
{
189-
if (!is_dir($dir)) {
190-
self::mkdir($dir);
191-
}
193+
if (!is_dir($dir)) self::mkdir($dir);
192194
THelpers::purge($dir);
193195
}
194196

0 commit comments

Comments
 (0)