Skip to content

Commit 0562890

Browse files
committed
#331 looks better with tests
(cherry picked from commit 1e22514)
1 parent d8ad7f7 commit 0562890

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ script:
3030
- php -f tests/NewCacheInstance.test.php
3131
- php -f tests/Psr6InterfaceImplements.test.php
3232
- php -f tests/AbstractProxy.test.php
33+
- php -f tests/AttachingDetachingMethods.test.php
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)