From 27afda94618ea0210e4f4f93c6b6de5c812ff8fd Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Thu, 29 Jun 2017 22:47:47 +0200 Subject: [PATCH 1/2] Added CustomNamespaces test --- tests/CustomNamespaces.test.php | 135 ++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 tests/CustomNamespaces.test.php diff --git a/tests/CustomNamespaces.test.php b/tests/CustomNamespaces.test.php new file mode 100644 index 000000000..adcdc7e8b --- /dev/null +++ b/tests/CustomNamespaces.test.php @@ -0,0 +1,135 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + */ + +use phpFastCache\CacheManager; +use phpFastCache\Helper\CacheConditionalHelper as CacheConditional; +use phpFastCache\Helper\TestHelper; +use Psr\Cache\CacheItemPoolInterface; + +chdir(__DIR__); +require_once __DIR__ . '/../src/autoload.php'; +$testHelper = new TestHelper('Custom namespaces'); + +$testDir = __DIR__ . '/../src/phpFastCache/CustomDriversPath/Files2/'; + +if (@!mkdir($testDir, 0777, true) && !is_dir($testDir)) +{ + $testHelper->printFailText('Cannot create CustomDriversPath directory'); + $testHelper->terminateTest(); +} + +/** + * The driver class string + */ +$driverClassString = << http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\CustomDriversPath\Files2; +use phpFastCache\Drivers\Files\Driver as FilesDriver; + +/** + * Class Driver + * @package phpFastCache\CustomDriversPath\Files2 + */ +class Driver extends FilesDriver +{ + +} +DRIVER_CLASS_STRING; + +/** + * The item class string + */ +$itemClassString = << http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\CustomDriversPath\Files2; +use phpFastCache\Drivers\Files\Item as FilesItem; + +/** + * Class Item + * @package phpFastCache\CustomDriversPath\Files2 + */ +class Item extends FilesItem +{ + +} +ITEM_CLASS_STRING; + + +/** + * Write the files + */ +file_put_contents("{$testDir}Driver.php", $driverClassString); +file_put_contents("{$testDir}Item.php", $itemClassString); + +/** + * Then adjust the Chmod + */ +chmod("{$testDir}Driver.php", 0644); +chmod("{$testDir}Item.php", 0644); + +CacheManager::setNamespacePath(phpFastCache\CustomDriversPath::class . '\\'); +$cacheInstance = CacheManager::getInstance('Files2', []); +$cacheKey = 'cacheKey'; +$RandomCacheValue = str_shuffle(uniqid('pfc', true)); + +/** + * Existing cache item test + */ +$cacheItem = $cacheInstance->getItem($cacheKey); +$RandomCacheValue = str_shuffle(uniqid('pfc', true)); +$cacheItem->set($RandomCacheValue); +$cacheInstance->save($cacheItem); + +/** + * Remove objects references + */ +$cacheInstance->detachAllItems(); +unset($cacheItem); + +$cacheValue = (new CacheConditional($cacheInstance))->get($cacheKey, function() use ($cacheKey, $testHelper, $RandomCacheValue){ + /** + * No parameter are passed + * to this closure + */ + $testHelper->printFailText('Unexpected closure call.'); + return $RandomCacheValue . '-1337'; +}); + +if($cacheValue === $RandomCacheValue){ + $testHelper->printPassText(sprintf('The cache promise successfully returned expected value "%s".', $cacheValue)); +}else{ + $testHelper->printFailText(sprintf('The cache promise returned an unexpected value "%s".', $cacheValue)); +} + +$cacheInstance->clear(); +$testHelper->terminateTest(); \ No newline at end of file From 2148104442eb635ba89cab5b0734b6b959988cae Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Thu, 29 Jun 2017 23:00:20 +0200 Subject: [PATCH 2/2] Updated CustomNamespaces test --- tests/CustomNamespaces.test.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/CustomNamespaces.test.php b/tests/CustomNamespaces.test.php index adcdc7e8b..2a96dac84 100644 --- a/tests/CustomNamespaces.test.php +++ b/tests/CustomNamespaces.test.php @@ -88,8 +88,16 @@ class Item extends FilesItem /** * Write the files */ -file_put_contents("{$testDir}Driver.php", $driverClassString); -file_put_contents("{$testDir}Item.php", $itemClassString); + + +if(!file_put_contents("{$testDir}Driver.php", $driverClassString) + || !file_put_contents("{$testDir}Item.php", $itemClassString) +){ + $testHelper->printFailText('The php files of driver "Files2" were not written'); + $testHelper->terminateTest(); +}else{ + $testHelper->printPassText('The php files of driver "Files2" were written'); +} /** * Then adjust the Chmod @@ -97,6 +105,15 @@ class Item extends FilesItem chmod("{$testDir}Driver.php", 0644); chmod("{$testDir}Item.php", 0644); +if(!class_exists(phpFastCache\CustomDriversPath\Files2\Item::class) + || !class_exists(phpFastCache\CustomDriversPath\Files2\Driver::class) +){ + $testHelper->printFailText('The php classes of driver "Files2" does not exists'); + $testHelper->terminateTest(); +}else{ + $testHelper->printPassText('The php classes of driver "Files2" were found'); +} + CacheManager::setNamespacePath(phpFastCache\CustomDriversPath::class . '\\'); $cacheInstance = CacheManager::getInstance('Files2', []); $cacheKey = 'cacheKey';