Skip to content

Commit

Permalink
Fixed #471 // "Fallback must be a boolean" error
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Jun 21, 2017
1 parent b3ec5aa commit e888e71
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/phpFastCache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ protected static function validateConfig(array $config)
}
break;
case 'fallback':
if(!is_bool($configValue)){
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
if(!is_bool($configValue) && !is_string($configValue)){
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean or string");
}
break;
case 'limited_memory_each_object':
Expand Down
52 changes: 52 additions & 0 deletions tests/issues/Github-471.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

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

use phpFastCache\CacheManager;
use phpFastCache\Drivers\Files\Driver as FilesDriver;
use phpFastCache\Helper\TestHelper;

chdir(__DIR__);
require_once __DIR__ . '/../../src/autoload.php';
$testHelper = new TestHelper('Github issue #471 - Fallback must be a boolean');
CacheManager::setDefaultConfig(['path' => __DIR__ . '/../../cache']);

/**
* Catch the E_USER_WARNING for the tests
*/
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) use($testHelper) {
if (0 === error_reporting()) {
return false;
}

if($errno === E_USER_WARNING){
define('E_USER_WARNING_RAISED', true);
}else{
$testHelper->printFailText('A unknown error (' . $errno . ') has been catched while the fallback driver got used.');
}
});

$cacheInstance = CacheManager::getInstance('Cassandra', ['fallback' => 'Files']);

if(defined('E_USER_WARNING_RAISED')){
$testHelper->printPassText('A E_USER_WARNING error has been catched while the fallback driver got used.');
}else{
$testHelper->printFailText('No E_USER_WARNING were thrown while the fallback driver got used.');
}

if($cacheInstance instanceof FilesDriver){
$key = 'test';
$cacheItem = $cacheInstance->getItem($key);
$cacheItem->set('value');
$cacheInstance->save($cacheItem);
$testHelper->printPassText('The variable $cacheInstance is an expected instance of FilesDriver');
}else if(is_object($cacheInstance)){
$testHelper->printFailText(sprintf('The variable $cacheInstance is an expected instance of "%s"', get_class($cacheInstance)));
}else{
$testHelper->printFailText(sprintf('The variable $cacheInstance is an expected variable type "%s"', gettype($cacheInstance)));
}

$testHelper->terminateTest();

0 comments on commit e888e71

Please sign in to comment.