Skip to content

Commit 985cb73

Browse files
committed
tests: TEMP_DIR replaced with getTempDir()
1 parent 127240a commit 985cb73

35 files changed

+58
-54
lines changed

tests/Bridges.DI/CacheExtension.phpt

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

1717
test(function () {
1818
$compiler = new DI\Compiler;
19-
$compiler->addExtension('cache', new CacheExtension(TEMP_DIR));
19+
$compiler->addExtension('cache', new CacheExtension(getTempDir()));
2020

2121
eval($compiler->compile());
2222

tests/Bridges.Latte/CacheMacro.cache.phpt

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

1515

1616
$latte = new Latte\Engine;
17-
$latte->setTempDirectory(TEMP_DIR);
17+
$latte->setTempDirectory(getTempDir());
1818
$latte->addMacro('cache', new CacheMacro($latte->getCompiler()));
1919
$latte->addProvider('cacheStorage', new Nette\Caching\Storages\DevNullStorage);
2020

tests/Storages/FileStorage.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require __DIR__ . '/../bootstrap.php';
1818
$key = [1, true];
1919
$value = range("\x00", "\xFF");
2020

21-
$cache = new Cache(new FileStorage(TEMP_DIR));
21+
$cache = new Cache(new FileStorage(getTempDir()));
2222

2323
Assert::null($cache->load($key));
2424

tests/Storages/FileStorage.call.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Mock
3030
}
3131

3232

33-
$cache = new Cache(new FileStorage(TEMP_DIR));
33+
$cache = new Cache(new FileStorage(getTempDir()));
3434
$mock = new Mock;
3535

3636
$called = false;

tests/Storages/FileStorage.callbacks.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR));
20+
$cache = new Cache(new FileStorage(getTempDir()));
2121

2222

2323
function dependency($val)

tests/Storages/FileStorage.clean-all.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Tester\Assert;
1414
require __DIR__ . '/../bootstrap.php';
1515

1616

17-
$storage = new FileStorage(TEMP_DIR);
17+
$storage = new FileStorage(getTempDir());
1818
$cacheA = new Cache($storage);
1919
$cacheB = new Cache($storage, 'B');
2020

tests/Storages/FileStorage.clean-namespace.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Tester\Assert;
1313

1414
require __DIR__ . '/../bootstrap.php';
1515

16-
$storage = new FileStorage(TEMP_DIR);
16+
$storage = new FileStorage(getTempDir());
1717

1818
/*
1919
* Create filestorage cache without namespace and some with namespaces

tests/Storages/FileStorage.closure.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require __DIR__ . '/../bootstrap.php';
1818
$key = '../' . implode('', range("\x00", "\x1F"));
1919
$value = range("\x00", "\xFF");
2020

21-
$cache = new Cache(new FileStorage(TEMP_DIR));
21+
$cache = new Cache(new FileStorage(getTempDir()));
2222

2323
Assert::null($cache->load($key));
2424

tests/Storages/FileStorage.const.001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR));
20+
$cache = new Cache(new FileStorage(getTempDir()));
2121

2222

2323
define('ANY_CONST', 10);

tests/Storages/FileStorage.const.002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $key = 'nette';
1818
$value = 'rulez';
1919

2020

21-
$cache = new Cache(new FileStorage(TEMP_DIR));
21+
$cache = new Cache(new FileStorage(getTempDir()));
2222

2323

2424
// Deleting dependent const

tests/Storages/FileStorage.deadlock.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Tester\Assert;
1414
require __DIR__ . '/../bootstrap.php';
1515

1616

17-
$storage = new FileStorage(TEMP_DIR);
17+
$storage = new FileStorage(getTempDir());
1818
$cache = new Cache($storage);
1919

2020
try {

tests/Storages/FileStorage.derive.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR), 'ns1');
20+
$cache = new Cache(new FileStorage(getTempDir()), 'ns1');
2121
$cache = $cache->derive('ns2');
2222

2323
$cache->save($key, $value);

tests/Storages/FileStorage.exceptions.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ require __DIR__ . '/../bootstrap.php';
1515

1616

1717
Assert::exception(function () {
18-
new FileStorage(TEMP_DIR . '/missing');
18+
new FileStorage(getTempDir() . '/missing');
1919
}, Nette\DirectoryNotFoundException::class, "Directory '%a%' not found.");
2020

2121

2222
Assert::exception(function () {
23-
$storage = new FileStorage(TEMP_DIR);
23+
$storage = new FileStorage(getTempDir());
2424
$storage->write('a', 'b', [Cache::TAGS => 'c']);
2525
}, Nette\InvalidStateException::class, 'CacheJournal has not been provided.');

tests/Storages/FileStorage.expiration.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR));
20+
$cache = new Cache(new FileStorage(getTempDir()));
2121

2222

2323
// Writing cache...

tests/Storages/FileStorage.files.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR));
20+
$cache = new Cache(new FileStorage(getTempDir()));
2121

2222

23-
$dependentFile = TEMP_DIR . '/spec.file';
23+
$dependentFile = getTempDir() . '/spec.file';
2424
@unlink($dependentFile);
2525

2626
// Writing cache...

tests/Storages/FileStorage.int.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require __DIR__ . '/../bootstrap.php';
1818
$key = 0;
1919
$value = range("\x00", "\xFF");
2020

21-
$cache = new Cache(new FileStorage(TEMP_DIR));
21+
$cache = new Cache(new FileStorage(getTempDir()));
2222

2323
Assert::null($cache->load($key));
2424

tests/Storages/FileStorage.items.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR));
20+
$cache = new Cache(new FileStorage(getTempDir()));
2121

2222

2323
// Writing cache...

tests/Storages/FileStorage.loadOrSave.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require __DIR__ . '/../bootstrap.php';
1818
$key = '../' . implode('', range("\x00", "\x1F"));
1919
$value = range("\x00", "\xFF");
2020

21-
$cache = new Cache(new FileStorage(TEMP_DIR));
21+
$cache = new Cache(new FileStorage(getTempDir()));
2222

2323
Assert::null($cache->load($key));
2424

tests/Storages/FileStorage.namespace.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Tester\Assert;
1414
require __DIR__ . '/../bootstrap.php';
1515

1616

17-
$storage = new FileStorage(TEMP_DIR);
17+
$storage = new FileStorage(getTempDir());
1818
$cacheA = new Cache($storage, 'a');
1919
$cacheB = new Cache($storage, 'b');
2020

tests/Storages/FileStorage.priority.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Tester\Assert;
1616
require __DIR__ . '/../bootstrap.php';
1717

1818

19-
$storage = new FileStorage(TEMP_DIR, new SQLiteJournal(TEMP_DIR . '/journal.s3db'));
19+
$storage = new FileStorage(getTempDir(), new SQLiteJournal(getTempDir() . '/journal.s3db'));
2020
$cache = new Cache($storage);
2121

2222

tests/Storages/FileStorage.sliding.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
1717
$key = 'nette';
1818
$value = 'rulez';
1919

20-
$cache = new Cache(new FileStorage(TEMP_DIR));
20+
$cache = new Cache(new FileStorage(getTempDir()));
2121

2222

2323
// Writing cache...

tests/Storages/FileStorage.start.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Tester\Assert;
1414
require __DIR__ . '/../bootstrap.php';
1515

1616

17-
$cache = new Cache(new FileStorage(TEMP_DIR));
17+
$cache = new Cache(new FileStorage(getTempDir()));
1818

1919

2020
ob_start();

tests/Storages/FileStorage.stress.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function checkStr($s)
3333
define('COUNT_FILES', 3);
3434

3535

36-
$storage = new FileStorage(TEMP_DIR);
36+
$storage = new FileStorage(getTempDir());
3737

3838

3939
// clear playground

tests/Storages/FileStorage.tags.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Tester\Assert;
1616
require __DIR__ . '/../bootstrap.php';
1717

1818

19-
$storage = new FileStorage(TEMP_DIR, new SQLiteJournal(TEMP_DIR . '/journal.s3db'));
19+
$storage = new FileStorage(getTempDir(), new SQLiteJournal(getTempDir() . '/journal.s3db'));
2020
$cache = new Cache($storage);
2121

2222

tests/Storages/FileStorage.wrap.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Test
3131
}
3232

3333

34-
$cache = new Cache(new FileStorage(TEMP_DIR));
34+
$cache = new Cache(new FileStorage(getTempDir()));
3535

3636
$called = false;
3737
Assert::same(55, $cache->wrap('mockFunction')(5, 50));

tests/Storages/Memcached.bulkRead.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!MemcachedStorage::isAvailable()) {
1818
Tester\Environment::skip('Requires PHP extension Memcached.');
1919
}
2020

21-
Tester\Environment::lock('memcached-files', TEMP_DIR);
21+
Tester\Environment::lock('memcached-files', getTempDir());
2222

2323

2424

tests/Storages/Memcached.expiration.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!MemcachedStorage::isAvailable()) {
1818
Tester\Environment::skip('Requires PHP extension Memcached.');
1919
}
2020

21-
Tester\Environment::lock('memcached-expiration', TEMP_DIR);
21+
Tester\Environment::lock('memcached-expiration', getTempDir());
2222

2323

2424
$key = 'nette-memcached-expiration-key';

tests/Storages/Memcached.files.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!MemcachedStorage::isAvailable()) {
1818
Tester\Environment::skip('Requires PHP extension Memcached.');
1919
}
2020

21-
Tester\Environment::lock('memcached-files', TEMP_DIR);
21+
Tester\Environment::lock('memcached-files', getTempDir());
2222

2323

2424
$key = 'nette-memcached-files-key';
@@ -27,7 +27,7 @@ $value = 'rulez';
2727
$cache = new Cache(new MemcachedStorage('localhost'));
2828

2929

30-
$dependentFile = TEMP_DIR . '/spec-memcached.file';
30+
$dependentFile = getTempDir() . '/spec-memcached.file';
3131
@unlink($dependentFile);
3232

3333
// Writing cache...

tests/Storages/Memcached.priority.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ if (!MemcachedStorage::isAvailable()) {
1919
Tester\Environment::skip('Requires PHP extension Memcached.');
2020
}
2121

22-
Tester\Environment::lock('memcached-priority', TEMP_DIR);
22+
Tester\Environment::lock('memcached-priority', getTempDir());
2323

2424

25-
$storage = new MemcachedStorage('localhost', 11211, '', new SQLiteJournal(TEMP_DIR . '/journal-memcached.s3db'));
25+
$storage = new MemcachedStorage('localhost', 11211, '', new SQLiteJournal(getTempDir() . '/journal-memcached.s3db'));
2626
$cache = new Cache($storage);
2727

2828

tests/Storages/Memcached.sliding.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!MemcachedStorage::isAvailable()) {
1818
Tester\Environment::skip('Requires PHP extension Memcached.');
1919
}
2020

21-
Tester\Environment::lock('memcached-sliding', TEMP_DIR);
21+
Tester\Environment::lock('memcached-sliding', getTempDir());
2222

2323

2424
$key = 'nette-memcached-sliding-key';

tests/Storages/Memcached.tags.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ if (!MemcachedStorage::isAvailable()) {
1919
Tester\Environment::skip('Requires PHP extension Memcached.');
2020
}
2121

22-
Tester\Environment::lock('memcached-tags', TEMP_DIR);
22+
Tester\Environment::lock('memcached-tags', getTempDir());
2323

2424

25-
$storage = new MemcachedStorage('localhost', 11211, '', new SQLiteJournal(TEMP_DIR . '/journal-memcached.s3db'));
25+
$storage = new MemcachedStorage('localhost', 11211, '', new SQLiteJournal(getTempDir() . '/journal-memcached.s3db'));
2626
$cache = new Cache($storage);
2727

2828

tests/Storages/SQLiteJournal.permissions.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (defined('PHP_WINDOWS_VERSION_BUILD')) {
2020

2121

2222
test(function () {
23-
$file = TEMP_DIR . '/sqlitejournal.permissions.1.sqlite';
23+
$file = getTempDir() . '/sqlitejournal.permissions.1.sqlite';
2424
Assert::false(file_exists($file));
2525

2626
umask(0);
@@ -31,7 +31,7 @@ test(function () {
3131

3232

3333
test(function () {
34-
$file = TEMP_DIR . '/sqlitejournal.permissions.2.sqlite';
34+
$file = getTempDir() . '/sqlitejournal.permissions.2.sqlite';
3535
Assert::false(file_exists($file));
3636

3737
umask(0077);

tests/Storages/SQLiteJournal.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SQLiteJournalTest extends IJournalTestCase
1919
public function createJournal()
2020
{
2121
static $id = 0;
22-
return new SQLiteJournal(TEMP_DIR . '/sqlitejournal_' . ++$id . '.sqlite');
22+
return new SQLiteJournal(getTempDir() . '/sqlitejournal_' . ++$id . '.sqlite');
2323
}
2424
}
2525

tests/Storages/SQLiteStorage.permissions.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (defined('PHP_WINDOWS_VERSION_BUILD')) {
2020

2121

2222
test(function () {
23-
$file = TEMP_DIR . '/sqlitestorage.permissions.1.sqlite';
23+
$file = getTempDir() . '/sqlitestorage.permissions.1.sqlite';
2424
Assert::false(file_exists($file));
2525

2626
umask(0);
@@ -31,7 +31,7 @@ test(function () {
3131

3232

3333
test(function () {
34-
$file = TEMP_DIR . '/sqlitestorage.permissions.2.sqlite';
34+
$file = getTempDir() . '/sqlitestorage.permissions.2.sqlite';
3535
Assert::false(file_exists($file));
3636

3737
umask(0077);

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
function test(\Closure $function): void

0 commit comments

Comments
 (0)