Skip to content

Commit 192e140

Browse files
authored
Merge pull request #389 from Geolim4/final
Added IO tests for disk-based drivers + Real array
2 parents ac789d3 + 3d611e1 commit 192e140

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

tests/ReadWriteOperations.test.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
5+
* @author Georges.L (Geolim4) <[email protected]>
6+
*/
7+
use phpFastCache\CacheManager;
8+
use phpFastCache\Core\Item\ExtendedCacheItemInterface;
9+
10+
chdir(__DIR__);
11+
require_once __DIR__ . '/../src/autoload.php';
12+
13+
$status = 0;
14+
echo "Testing read/write operations\n";
15+
16+
CacheManager::setDefaultConfig(array('path' => __DIR__ . '/../../cache'));
17+
18+
/**
19+
* @var $items ExtendedCacheItemInterface[]
20+
*/
21+
$items = [];
22+
$instances = [];
23+
$keys = [];
24+
25+
$dirs = [
26+
__DIR__ . '/../var/cache/IO-',
27+
sys_get_temp_dir() . '/phpfastcache/IO-1',
28+
sys_get_temp_dir() . '/phpfastcache/IO-2'
29+
];
30+
31+
32+
foreach ($dirs as $dirIndex => $dir) {
33+
for ($i = 1; $i <= 10; $i++)
34+
{
35+
$keys[$dirIndex][] = 'test' . $i;
36+
}
37+
38+
for ($i = 1; $i <= 10; $i++)
39+
{
40+
$cacheInstanceName = 'cacheInstance' . $i;
41+
42+
$instances[$dirIndex][$cacheInstanceName] = CacheManager::getInstance('Files',array('path' => $dir . str_pad($i, 3, '0', STR_PAD_LEFT)));
43+
44+
foreach($keys[$dirIndex] as $index => $key)
45+
{
46+
$items[$dirIndex][$index] = $instances[$dirIndex][$cacheInstanceName]->getItem($key);
47+
$items[$dirIndex][$index]->set("test-$dirIndex-$index")->expiresAfter(600);
48+
$instances[$dirIndex][$cacheInstanceName]->saveDeferred($items[$dirIndex][$index]);
49+
}
50+
$instances[$dirIndex][$cacheInstanceName]->commit();
51+
$instances[$dirIndex][$cacheInstanceName]->detachAllItems();
52+
}
53+
54+
foreach($instances[$dirIndex] as $cacheInstanceName => $instance)
55+
{
56+
foreach($keys[$dirIndex] as $index => $key)
57+
{
58+
if($instances[$dirIndex][$cacheInstanceName]->getItem($key)->get() === "test-$dirIndex-$index")
59+
{
60+
echo "[PASS] Item #{$key} of instance #{$cacheInstanceName} of dir #{$dirIndex} has returned the expected value (" . gettype("test-$dirIndex-$index") . ":'" . "test-$dirIndex-$index" . "')\n";
61+
}
62+
else
63+
{
64+
echo "[FAIL] Item #{$key} of instance #{$cacheInstanceName} of dir #{$dirIndex} returned an unexpected value (" . gettype($instances[$dirIndex][$cacheInstanceName]->getItem($key)->get()) . ":'" . $instances[$dirIndex][$cacheInstanceName]->getItem($key)->get() . "') expected (" . gettype("test-$dirIndex-$index") . ":'" . "test-$dirIndex-$index" . "') \n";
65+
$status = 255;
66+
}
67+
}
68+
$instances[$dirIndex][$cacheInstanceName]->detachAllItems();
69+
}
70+
}
71+
72+
exit($status);

tests/issues/Github-373.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$status = 0;
1313
echo "Testing Github issue #373 - Files driver issue after clearing cache\n";
1414

15-
CacheManager::setDefaultConfig(array('path' => __DIR__ . '/../../cache'));
15+
CacheManager::setDefaultConfig(['path' => __DIR__ . '/../../cache']);
1616
$cacheInstance = CacheManager::getInstance('Files');
1717

1818
$key = 'test';

0 commit comments

Comments
 (0)