Skip to content

Commit

Permalink
Added test for custom predis client
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed May 15, 2018
1 parent cdfaf01 commit e507a8b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/PredisCustomClient.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*/

use Phpfastcache\CacheManager;
use Phpfastcache\Helper\TestHelper;
use Phpfastcache\Drivers\Predis\Config as PredisConfig;
use Predis\Client as PredisClient;

chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$testHelper = new TestHelper('Predis custom client');

try{
$predisClient = new PredisClient([
'host' => '127.0.0.1',
'port' => 6379,
'password' => null,
'database' => 0,
]);
$predisClient->connect();

$cacheInstance = CacheManager::getInstance('Predis', (new PredisConfig())->setPredisClient($predisClient));
$cacheKey = 'predisCustomClient';
$cacheItem = $cacheInstance->getItem($cacheKey);
$cacheItem->set(1337);
$cacheInstance->save($cacheItem);
$cacheInstance->detachAllItems();
unset($cacheItem);
if($cacheInstance->getItem($cacheKey)->get() === 1337){
$testHelper->printPassText('Successfully written and read data from outside Predis client');
}else{
$testHelper->printFailText('Error writing or reading data from outside Predis client');
}
}catch (\RedisException $e){
$testHelper->printFailText('A Predis exception occurred: ' . $e->getMessage());
}

$testHelper->terminateTest();

0 comments on commit e507a8b

Please sign in to comment.