Skip to content

Commit 0f1aba6

Browse files
committed
improved tests
1 parent 25a2f81 commit 0f1aba6

7 files changed

Lines changed: 131 additions & 49 deletions

File tree

tests/Bridges.Latte3/expected/cache.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
%A%
3-
if ($this->global->cache->createCache('%a%')) /* line %a% */
3+
if ($this->global->cache->createCache('%a%')) /* %a% */
44
try {
55
echo ' ';
6-
echo LR\%a%(($this->filters->lower)($title)) /* line %a% */;
6+
echo LR\%a%(($this->filters->lower)($title)) /* %a% */;
77
echo "\n";
88

9-
$this->global->cache->end() /* line %a% */;
9+
$this->global->cache->end() /* %a% */;
1010
} catch (\Throwable $ʟ_e) {
1111
$this->global->cache->rollback();
1212
throw $ʟ_e;

tests/Bridges.Latte3/expected/cache.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
echo 'Noncached content
44
55
';
6-
if ($this->global->cache->createCache('%a%', [$id, 'tags' => 'mytag'])) /* line %a% */
6+
if ($this->global->cache->createCache('%a%', [$id, 'tags' => 'mytag'])) /* %a% */
77
try {
88
echo '
99
<h1>';
10-
echo LR\%a%(($this->filters->upper)($title)) /* line %a% */;
10+
echo LR\%a%(($this->filters->upper)($title)) /* %a% */;
1111
echo '</h1>
1212
1313
';
14-
$this->createTemplate('include.cache.latte', ['localvar' => 11] + $this->params, 'include')->renderToContentType('html') /* line %a% */;
14+
$this->createTemplate('include.cache.latte', ['localvar' => 11] + $this->params, 'include')->renderToContentType('html') /* %a% */;
1515
echo "\n";
1616

17-
$this->global->cache->end() /* line %a% */;
17+
$this->global->cache->end() /* %a% */;
1818
} catch (\Throwable $ʟ_e) {
1919
$this->global->cache->rollback();
2020
throw $ʟ_e;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Test: Nette\Caching\Storages\FileStorage sliding expiration test.
5+
*/
6+
7+
use Nette\Caching\Cache;
8+
use Nette\Caching\Storages\FileStorage;
9+
use Tester\Assert;
10+
11+
12+
require __DIR__ . '/../bootstrap.php';
13+
14+
15+
$key = 'nette';
16+
$value = 'rulez';
17+
18+
$cache = new Cache(new FileStorage(getTempDir()));
19+
20+
21+
// Writing cache...
22+
$cache->save($key, $value, [
23+
Cache::Expire => time() + 3,
24+
Cache::Sliding => true,
25+
]);
26+
27+
28+
for ($i = 0; $i < 5; $i++) {
29+
// Sleeping 1 second
30+
sleep(1);
31+
clearstatcache();
32+
33+
Assert::truthy($cache->bulkLoad([$key])[$key]);
34+
}
35+
36+
// Sleeping few seconds...
37+
sleep(5);
38+
clearstatcache();
39+
40+
Assert::null($cache->bulkLoad([$key])[$key]);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Test: Nette\Caching\Storages\MemcachedStorage sliding expiration test.
5+
*/
6+
7+
use Nette\Caching\Cache;
8+
use Nette\Caching\Storages\MemcachedStorage;
9+
use Tester\Assert;
10+
11+
12+
require __DIR__ . '/../bootstrap.php';
13+
14+
15+
if (!MemcachedStorage::isAvailable()) {
16+
Tester\Environment::skip('Requires PHP extension Memcached.');
17+
}
18+
19+
Tester\Environment::lock('memcached-sliding', getTempDir());
20+
21+
22+
$key = 'nette-memcached-sliding-key';
23+
$value = 'rulez';
24+
25+
$cache = new Cache(new MemcachedStorage('localhost'));
26+
27+
28+
// Writing cache...
29+
$cache->save($key, $value, [
30+
Cache::Expire => time() + 3,
31+
Cache::Sliding => true,
32+
]);
33+
34+
35+
for ($i = 0; $i < 5; $i++) {
36+
// Sleeping 1 second
37+
sleep(1);
38+
39+
Assert::truthy($cache->bulkLoad([$key])[$key]);
40+
}
41+
42+
// Sleeping few seconds...
43+
sleep(5);
44+
45+
Assert::null($cache->bulkLoad([$key])[$key]);

tests/Storages/Memcached.sliding.phpt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,3 @@ for ($i = 0; $i < 5; $i++) {
4343
sleep(5);
4444

4545
Assert::null($cache->load($key));
46-
47-
48-
// Bulk
49-
50-
// Writing cache...
51-
$cache->save($key, $value, [
52-
Cache::Expire => time() + 3,
53-
Cache::Sliding => true,
54-
]);
55-
56-
57-
for ($i = 0; $i < 5; $i++) {
58-
// Sleeping 1 second
59-
sleep(1);
60-
61-
Assert::truthy($cache->bulkLoad([$key])[$key]);
62-
}
63-
64-
// Sleeping few seconds...
65-
sleep(5);
66-
67-
Assert::null($cache->load([$key]));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Test: Nette\Caching\Storages\SQLiteStorage expiration test.
5+
* @phpExtension pdo_sqlite
6+
*/
7+
8+
use Nette\Caching\Cache;
9+
use Nette\Caching\Storages\SQLiteStorage;
10+
use Tester\Assert;
11+
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
16+
$key = 'nette';
17+
$value = 'rulez';
18+
19+
$cache = new Cache(new SQLiteStorage(':memory:'));
20+
21+
22+
// Writing cache...
23+
$cache->save($key, $value, [
24+
Cache::Expire => time() + 3,
25+
Cache::Sliding => true,
26+
]);
27+
28+
29+
for ($i = 0; $i < 5; $i++) {
30+
// Sleeping 1 second
31+
sleep(1);
32+
33+
Assert::truthy($cache->bulkLoad([$key])[$key]);
34+
}
35+
36+
// Sleeping few seconds...
37+
sleep(5);
38+
39+
Assert::null($cache->bulkLoad([$key])[$key]);

tests/Storages/SQLiteStorage.sliding.phpt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,3 @@ for ($i = 0; $i < 5; $i++) {
3737
sleep(5);
3838

3939
Assert::null($cache->load($key));
40-
41-
42-
// Writing cache...
43-
$cache->save($key, $value, [
44-
Cache::Expire => time() + 3,
45-
Cache::Sliding => true,
46-
]);
47-
48-
49-
for ($i = 0; $i < 5; $i++) {
50-
// Sleeping 1 second
51-
sleep(1);
52-
53-
Assert::truthy($cache->bulkLoad([$key])[$key]);
54-
}
55-
56-
// Sleeping few seconds...
57-
sleep(5);
58-
59-
Assert::null($cache->bulkLoad([$key])[$key]);

0 commit comments

Comments
 (0)