Skip to content

Commit

Permalink
Environment: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 13, 2016
1 parent 533b1ec commit ab0abe6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Environment.php
Expand Up @@ -4,6 +4,7 @@

use Nette\Caching\Storages\FileStorage;
use Nette\Loaders\RobotLoader;
use RuntimeException;
use Tester\Environment as TEnvironment;
use Tester\Helpers as THelpers;

Expand Down Expand Up @@ -67,8 +68,6 @@ public static function setupTimezone($timezone = 'Europe/Prague')
*/
public static function setupVariables($testerDir)
{
clearstatcache();

if (!is_dir($testerDir)) {
die(sprintf('Provide existing folder, "%s" does not exist.', $testerDir));
}
Expand All @@ -93,8 +92,13 @@ public static function setupVariables($testerDir)
ini_set('session.save_path', TEMP_DIR);

// Create folders
self::mkdir(TEMP_DIR);
clearstatcache(TRUE, TMP_DIR);
self::mkdir(TMP_DIR);
clearstatcache(TRUE, CACHE_DIR);
self::mkdir(CACHE_DIR);
clearstatcache(TRUE, TEMP_DIR);
self::mkdir(TEMP_DIR);
clearstatcache(TRUE, TEMP_DIR);
self::purge(TEMP_DIR);
}

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

/**
* @param string $dir
* @param int $mask
* @param int $mode
* @param bool $recursive
* @return void
*/
public static function mkdir($dir, $mode = 0777, $recursive = TRUE)
{
clearstatcache();
if (!is_dir($dir) && !@mkdir($dir, $mode, $recursive)) { // @ - dir may already exist
if (is_dir($dir) === FALSE && @mkdir($dir, $mode, $recursive) === FALSE) {
clearstatcache(TRUE, $dir);
$error = error_get_last();
if (!is_dir($dir)) {
if (is_dir($dir) === FALSE && !file_exists($dir) === FALSE) {
throw new RuntimeException("Unable to create directory '$dir'. " . $error['message']);
}
}
Expand All @@ -186,9 +190,7 @@ public static function rmdir($dir)
*/
private static function purge($dir)
{
if (!is_dir($dir)) {
self::mkdir($dir);
}
if (!is_dir($dir)) self::mkdir($dir);
THelpers::purge($dir);
}

Expand Down

0 comments on commit ab0abe6

Please sign in to comment.