forked from TruCopilot/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCacheItemAtomicMethods.test.php
More file actions
56 lines (44 loc) · 1.7 KB
/
CacheItemAtomicMethods.test.php
File metadata and controls
56 lines (44 loc) · 1.7 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
<?php
/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
use Phpfastcache\CacheManager;
use Phpfastcache\Exceptions\PhpfastcacheInstanceNotFoundException;
use Phpfastcache\Tests\Helper\TestHelper;
chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$testHelper = new TestHelper('Cache Item Atomic Methods');
$defaultDriver = (!empty($argv[1]) ? ucfirst($argv[1]) : 'Files');
$driverInstance = CacheManager::getInstance($defaultDriver);
$testItem = $driverInstance->getItem('test-item');
$cacheTestData = 'I <3 PhpFastCache';
$testItem->set($cacheTestData)->expiresAfter(600);
$driverInstance->save($testItem);
unset($testItem);
$driverInstance->detachAllItems();
$testItem = $driverInstance->getItem('test-item');
if ($testItem->getLength() === \strlen($cacheTestData)) {
$testHelper->assertPass('Atomic method getLength() returned the exact length');
} else {
$testHelper->assertPass('Atomic method getLength() returned an unexpected length' . $testItem->getLength());
}
if (!$testItem->isNull()) {
$testHelper->assertPass('Atomic method isNull() returned FALSE');
} else {
$testHelper->assertPass('Atomic method isNull() returned TRUE');
}
if (!$testItem->isEmpty()) {
$testHelper->assertPass('Atomic method isEmpty() returned FALSE');
} else {
$testHelper->assertPass('Atomic method isEmpty() returned TRUE');
}
$testHelper->terminateTest();