1+ <?php
2+
3+ /**
4+ * @author Khoa Bui (khoaofgod) <[email protected] > http://www.phpfastcache.com 5+ * @author Georges.L (Geolim4) <[email protected] > 6+ */
7+
8+ use phpFastCache \CacheManager ;
9+ use phpFastCache \Core \Pool \ExtendedCacheItemPoolInterface ;
10+ use Psr \Cache \CacheItemPoolInterface ;
11+
12+
13+ chdir (__DIR__ );
14+ require_once __DIR__ . '/../vendor/autoload.php ' ;
15+
16+ $ status = 0 ;
17+ echo "Testing [a|de]ttaching methods \n" ;
18+
19+ /**
20+ * Testing memcached as it is declared in .travis.yml
21+ */
22+ $ driverInstance = CacheManager::getInstance ('Files ' );
23+
24+ if (!is_object ($ driverInstance )) {
25+ echo '[FAIL] CacheManager::getInstance() returned an invalid variable type: ' . gettype ($ driverInstance ) . "\n" ;
26+ $ status = 1 ;
27+ }else if (!($ driverInstance instanceof CacheItemPoolInterface)){
28+ echo '[FAIL] CacheManager::getInstance() returned an invalid class: ' . get_class ($ driverInstance ) . "\n" ;
29+ $ status = 1 ;
30+ }else {
31+ $ key = 'test_attaching_detaching ' ;
32+
33+ $ itemDetached = $ driverInstance ->getItem ($ key );
34+ $ driverInstance ->detachItem ($ itemDetached );
35+ $ itemAttached = $ driverInstance ->getItem ($ key );
36+
37+ if (!$ driverInstance ->isAttached ($ itemDetached ))
38+ {
39+ echo '[PASS] ExtendedCacheItemPoolInterface::isAttached() identified $itemDetached as being detached. ' . "\n" ;
40+ }
41+ else
42+ {
43+ echo '[FAIL] ExtendedCacheItemPoolInterface::isAttached() failed to identify $itemDetached as to be detached. ' . "\n" ;
44+ $ status = 1 ;
45+ }
46+
47+ try {
48+ $ driverInstance ->attachItem ($ itemDetached );
49+ echo '[FAIL] ExtendedCacheItemPoolInterface::attachItem() attached $itemDetached without trowing an error. ' . "\n" ;
50+ $ status = 1 ;
51+ }catch (\LogicException $ e ){
52+ echo '[PASS] ExtendedCacheItemPoolInterface::attachItem() failed to attach $itemDetached by trowing a LogicException exception. ' . "\n" ;
53+ }
54+
55+ }
56+
57+ exit ($ status );
0 commit comments