Skip to content

Commit c690255

Browse files
committed
tests: TEMP_DIR replaced with getTempDir()
1 parent 8fb996f commit c690255

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

tests/Latte/BlockMacros.include.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php';
1313

1414

1515
$latte = new Latte\Engine;
16-
$latte->setTempDirectory(TEMP_DIR);
16+
$latte->setTempDirectory(getTempDir());
1717

1818
Assert::matchFile(
1919
__DIR__ . '/expected/BlockMacros.include.phtml',

tests/Latte/Engine.parseError.php7.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Assert::exception(function () {
2020

2121
Assert::exception(function () {
2222
$latte = new Latte\Engine;
23-
$latte->setTempDirectory(TEMP_DIR);
23+
$latte->setTempDirectory(getTempDir());
2424
$latte->setLoader(new Latte\Loaders\StringLoader);
2525
$latte->render('{php * * }');
2626
}, ParseError::class, "syntax error, unexpected '*'");

tests/Latte/Engine.warmupCache.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test(function () {
1515
$template = __DIR__ . '/templates/general.latte';
1616

1717
$latte = new Latte\Engine;
18-
$latte->setTempDirectory(TEMP_DIR);
18+
$latte->setTempDirectory(getTempDir());
1919

2020
$cachedFile = $latte->getCacheFile($template);
2121
Assert::false(file_exists($cachedFile));

tests/bootstrap.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@
1616
date_default_timezone_set('Europe/Prague');
1717

1818

19-
// create temporary directory
20-
(function () {
21-
define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid());
22-
23-
// garbage collector
24-
$GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
25-
if (rand(0, 100)) {
26-
flock($lock, LOCK_SH);
27-
@mkdir(dirname(TEMP_DIR));
28-
} elseif (flock($lock, LOCK_EX)) {
29-
Tester\Helpers::purge(dirname(TEMP_DIR));
19+
function getTempDir(): string
20+
{
21+
$dir = __DIR__ . '/tmp/' . getmypid();
22+
23+
if (empty($GLOBALS['\\lock'])) {
24+
// garbage collector
25+
$GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
26+
if (rand(0, 100)) {
27+
flock($lock, LOCK_SH);
28+
@mkdir(dirname($dir));
29+
} elseif (flock($lock, LOCK_EX)) {
30+
Tester\Helpers::purge(dirname($dir));
31+
}
32+
33+
@mkdir($dir);
3034
}
3135

32-
@mkdir(TEMP_DIR);
33-
})();
36+
return $dir;
37+
}
3438

3539

3640
// output buffer level check

0 commit comments

Comments
 (0)