forked from PHPSocialNetwork/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomNamespaces.test.php
More file actions
152 lines (127 loc) · 3.83 KB
/
CustomNamespaces.test.php
File metadata and controls
152 lines (127 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*/
use phpFastCache\CacheManager;
use phpFastCache\Helper\CacheConditionalHelper as CacheConditional;
use phpFastCache\Helper\TestHelper;
use Psr\Cache\CacheItemPoolInterface;
chdir(__DIR__);
require_once __DIR__ . '/../src/autoload.php';
$testHelper = new TestHelper('Custom namespaces');
$testDir = __DIR__ . '/../src/phpFastCache/CustomDriversPath/Files2/';
if (@!mkdir($testDir, 0777, true) && !is_dir($testDir))
{
$testHelper->printFailText('Cannot create CustomDriversPath directory');
$testHelper->terminateTest();
}
/**
* The driver class string
*/
$driverClassString = <<<DRIVER_CLASS_STRING
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*
*/
namespace phpFastCache\CustomDriversPath\Files2;
use phpFastCache\Drivers\Files\Driver as FilesDriver;
/**
* Class Driver
* @package phpFastCache\CustomDriversPath\Files2
*/
class Driver extends FilesDriver
{
}
DRIVER_CLASS_STRING;
/**
* The item class string
*/
$itemClassString = <<<ITEM_CLASS_STRING
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*
*/
namespace phpFastCache\CustomDriversPath\Files2;
use phpFastCache\Drivers\Files\Item as FilesItem;
/**
* Class Item
* @package phpFastCache\CustomDriversPath\Files2
*/
class Item extends FilesItem
{
}
ITEM_CLASS_STRING;
/**
* Write the files
*/
if(!file_put_contents("{$testDir}Driver.php", $driverClassString)
|| !file_put_contents("{$testDir}Item.php", $itemClassString)
){
$testHelper->printFailText('The php files of driver "Files2" were not written');
$testHelper->terminateTest();
}else{
$testHelper->printPassText('The php files of driver "Files2" were written');
}
/**
* Then adjust the Chmod
*/
chmod("{$testDir}Driver.php", 0644);
chmod("{$testDir}Item.php", 0644);
if(!class_exists(phpFastCache\CustomDriversPath\Files2\Item::class)
|| !class_exists(phpFastCache\CustomDriversPath\Files2\Driver::class)
){
$testHelper->printFailText('The php classes of driver "Files2" does not exists');
$testHelper->terminateTest();
}else{
$testHelper->printPassText('The php classes of driver "Files2" were found');
}
CacheManager::setNamespacePath(phpFastCache\CustomDriversPath::class);
$cacheInstance = CacheManager::getInstance('Files2', []);
$cacheKey = 'cacheKey';
$RandomCacheValue = str_shuffle(uniqid('pfc', true));
/**
* Existing cache item test
*/
$cacheItem = $cacheInstance->getItem($cacheKey);
$RandomCacheValue = str_shuffle(uniqid('pfc', true));
$cacheItem->set($RandomCacheValue);
$cacheInstance->save($cacheItem);
/**
* Remove objects references
*/
$cacheInstance->detachAllItems();
unset($cacheItem);
$cacheValue = (new CacheConditional($cacheInstance))->get($cacheKey, function() use ($cacheKey, $testHelper, $RandomCacheValue){
/**
* No parameter are passed
* to this closure
*/
$testHelper->printFailText('Unexpected closure call.');
return $RandomCacheValue . '-1337';
});
if($cacheValue === $RandomCacheValue){
$testHelper->printPassText(sprintf('The cache promise successfully returned expected value "%s".', $cacheValue));
}else{
$testHelper->printFailText(sprintf('The cache promise returned an unexpected value "%s".', $cacheValue));
}
$cacheInstance->clear();
$testHelper->terminateTest();