diff --git a/.travis.yml b/.travis.yml index 870562e8..2798fde0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ matrix: - php: hhvm script: - - vendor/bin/tester tests -s -c tests/php-unix.ini + - vendor/bin/tester tests -s -p php -c tests/php-unix.ini - php code-checker/src/code-checker.php after_failure: @@ -24,4 +24,4 @@ services: before_script: # Install Nette Tester & Code Checker - composer install --no-interaction --dev --prefer-source - - composer create-project nette/code-checker code-checker ~2.2 --no-interaction --prefer-source + - composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source diff --git a/composer.json b/composer.json index 85509ab7..fc7ce17f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { "nette/tester": "~1.0", - "latte/latte": "~2.2.2" + "latte/latte": "~2.3" }, "conflict": { "nette/nette": "<2.2" diff --git a/contributing.md b/contributing.md new file mode 100644 index 00000000..a1cbbd53 --- /dev/null +++ b/contributing.md @@ -0,0 +1,27 @@ +How to contribute & use the issue tracker +========================================= + +The issue tracker is the preferred channel for bug reports, features requests +and submitting pull requests, but please respect the following restrictions: + +* Please **do not** use the issue tracker for personal support requests (use + [Nette forum](http://forum.nette.org) or [Stack Overflow](http://stackoverflow.com)). + +* Please **do not** derail or troll issues. Keep the discussion on topic and + respect the opinions of others. + +* Use the GitHub **issue search** — check if the issue has already been + reported. + +A good **bug report** shouldn't leave others needing to chase you up for more +information. Please try to be as detailed as possible in your report. + +**Feature requests** are welcome. But take a moment to find out whether your idea +fits with the scope and aims of the project. It's up to *you* to make a strong +case to convince the project's developers of the merits of this feature. + +Nette welcomes **pull requests**. If you'd like to contribute, please take a moment +to [read the guidelines](http://nette.org/en/contributing) in order to make +the contribution process easy and effective for everyone involved. + +Thanks! diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index 82113cda..77040254 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -98,7 +98,9 @@ public function load($key, $fallback = NULL) { $data = $this->storage->read($this->generateKey($key)); if ($data === NULL && $fallback) { - return $this->save($key, Callback::closure($fallback)); + return $this->save($key, function(& $dependencies) use ($fallback) { + return call_user_func_array($fallback, array(& $dependencies)); + }); } return $data; } @@ -209,7 +211,9 @@ public function clean(array $conditions = NULL) public function call($function) { $key = func_get_args(); - $key[0] = Callback::toReflection($function); + if (is_array($function) && is_object($function[0])) { + $key[0][0] = get_class($function[0]); + } return $this->load($key, function() use ($function, $key) { return Callback::invokeArgs($function, array_slice($key, 1)); }); @@ -226,7 +230,10 @@ public function wrap($function, array $dependencies = NULL) { $cache = $this; return function() use ($cache, $function, $dependencies) { - $key = array(Callback::toReflection($function), func_get_args()); + $key = array($function, func_get_args()); + if (is_array($function) && is_object($function[0])) { + $key[0][0] = get_class($function[0]); + } $data = $cache->load($key); if ($data === NULL) { $data = $cache->save($key, Callback::invokeArgs($function, $key[1]), $dependencies); diff --git a/tests/Caching.Latte/expected/CacheMacro.cache.inc.phtml b/tests/Caching.Latte/expected/CacheMacro.cache.inc.phtml index 3e8b67a3..210ef852 100644 --- a/tests/Caching.Latte/expected/CacheMacro.cache.inc.phtml +++ b/tests/Caching.Latte/expected/CacheMacro.cache.inc.phtml @@ -1,6 +1,5 @@ lower($title), ENT_NOQUOTES) ?> tmp = array_pop($_g->caches); if (!$_l->tmp instanceof stdClass) $_l->tmp->end(); } +%A% diff --git a/tests/Caching.Latte/expected/CacheMacro.cache.phtml b/tests/Caching.Latte/expected/CacheMacro.cache.phtml index 602f1423..d071ae64 100644 --- a/tests/Caching.Latte/expected/CacheMacro.cache.phtml +++ b/tests/Caching.Latte/expected/CacheMacro.cache.phtml @@ -1,6 +1,5 @@ templates['%[a-z0-9]+%']->renderChildTemplate('include.cache.latte', array('localvar' => 11) + $template->getParameters()) ?> tmp = array_pop($_g->caches); if (!$_l->tmp instanceof stdClass) $_l->tmp->end(); } +%A% diff --git a/tests/Caching/Cache.load.phpt b/tests/Caching/Cache.load.phpt index 9162358a..0fb9675a 100644 --- a/tests/Caching/Cache.load.phpt +++ b/tests/Caching/Cache.load.phpt @@ -28,7 +28,7 @@ $data = $cache->load('key', function() { Assert::equal('value', $data['data']); -// load twice with fallback, pass dependencies +// load twice with closure fallback, pass dependencies $dependencies = array(Cache::TAGS => 'tag'); $storage = new TestStorage(); $cache = new Cache($storage, 'ns'); @@ -44,3 +44,17 @@ $data = $cache->load('key', function() { }); Assert::equal('value', $data['data']); Assert::equal($dependencies, $data['dependencies']); + + +// load twice with fallback, pass dependencies +function fallback(& $deps) { + global $dependencies; + $deps = $dependencies; + return 'value'; +} + +$value = $cache->load('key2', 'fallback'); +Assert::equal('value', $value); +$data = $cache->load('key2'); +Assert::equal('value', $data['data']); +Assert::equal($dependencies, $data['dependencies']); diff --git a/tests/Caching/Cache.save.phpt b/tests/Caching/Cache.save.phpt index c18d9ad2..2187b421 100644 --- a/tests/Caching/Cache.save.phpt +++ b/tests/Caching/Cache.save.phpt @@ -20,8 +20,9 @@ $dependencies = array(Cache::TAGS => 'tag'); $cache->save('key', 'value', $dependencies); -Assert::equal('value', $cache['key']['data']); -Assert::equal($dependencies, $cache['key']['dependencies']); +$res = $cache->load('key'); +Assert::equal('value', $res['data']); +Assert::equal($dependencies, $res['dependencies']); // save callback return value @@ -32,8 +33,9 @@ $cache->save('key', function() { return 'value'; }); -Assert::equal('value', $cache['key']['data']); -Assert::equal(array(), $cache['key']['dependencies']); +$res = $cache->load('key'); +Assert::equal('value', $res['data']); +Assert::equal(array(), $res['dependencies']); // save callback return value with dependencies @@ -45,5 +47,6 @@ $cache->save('key', function() { return 'value'; }, $dependencies); -Assert::equal('value', $cache['key']['data']); -Assert::equal($dependencies, $cache['key']['dependencies']); +$res = $cache->load('key'); +Assert::equal('value', $res['data']); +Assert::equal($dependencies, $res['dependencies']); diff --git a/tests/Caching/DevNullStorage.phpt b/tests/Caching/DevNullStorage.phpt index c2eb02a9..589abc4e 100644 --- a/tests/Caching/DevNullStorage.phpt +++ b/tests/Caching/DevNullStorage.phpt @@ -19,27 +19,23 @@ $value = '"Hello World"'; $cache = new Cache(new DevNullStorage, 'myspace'); -Assert::false( isset($cache[$key]) ); - -Assert::null( $cache[$key] ); +Assert::null( $cache->load($key) ); // Writing cache... -$cache[$key] = $value; - -Assert::false( isset($cache[$key]) ); +$cache->save($key, $value); -Assert::notSame( $cache[$key], $value ); +Assert::null( $cache->load($key) ); -// Removing from cache using unset()... -unset($cache[$key]); +// Removing from cache using remove()... +$cache->remove($key); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Removing from cache using set NULL... -$cache[$key] = $value; -$cache[$key] = NULL; +$cache->save($key, $value); +$cache->save($key, NULL); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.basic.phpt b/tests/Caching/FileStorage.basic.phpt index d6bb5534..f8d4d91b 100644 --- a/tests/Caching/FileStorage.basic.phpt +++ b/tests/Caching/FileStorage.basic.phpt @@ -18,30 +18,26 @@ $value = range("\x00", "\xFF"); $cache = new Cache(new FileStorage(TEMP_DIR)); -Assert::false( isset($cache[$key]) ); - -Assert::null( $cache[$key] ); +Assert::null( $cache->load($key) ); // Writing cache... -$cache[$key] = $value; - -Assert::true( isset($cache[$key]) ); +$cache->save($key, $value); -Assert::same( $cache[$key], $value ); +Assert::same( $cache->load($key), $value ); -// Removing from cache using unset()... -unset($cache[$key]); +// Removing from cache using remove()... +$cache->remove($key); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Removing from cache using set NULL... -$cache[$key] = $value; -$cache[$key] = NULL; +$cache->save($key, $value); +$cache->save($key, NULL); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache... diff --git a/tests/Caching/FileStorage.callbacks.phpt b/tests/Caching/FileStorage.callbacks.phpt index 8863979f..3e00ad44 100644 --- a/tests/Caching/FileStorage.callbacks.phpt +++ b/tests/Caching/FileStorage.callbacks.phpt @@ -29,7 +29,7 @@ $cache->save($key, $value, array( Cache::CALLBACKS => array(array('dependency', 1)), )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Writing cache... @@ -37,4 +37,4 @@ $cache->save($key, $value, array( Cache::CALLBACKS => array(array('dependency', 0)), )); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.clean-all.phpt b/tests/Caching/FileStorage.clean-all.phpt index 73c33287..ee1950a7 100644 --- a/tests/Caching/FileStorage.clean-all.phpt +++ b/tests/Caching/FileStorage.clean-all.phpt @@ -16,24 +16,21 @@ $storage = new FileStorage(TEMP_DIR); $cacheA = new Cache($storage); $cacheB = new Cache($storage,'B'); -$cacheA['test1'] = 'David'; -$cacheA['test2'] = 'Grudl'; -$cacheB['test1'] = 'divaD'; -$cacheB['test2'] = 'ldurG'; +$cacheA->save('test1', 'David'); +$cacheA->save('test2', 'Grudl'); +$cacheB->save('test1', 'divaD'); +$cacheB->save('test2', 'ldurG'); Assert::same( 'David Grudl divaD ldurG', implode(' ',array( - $cacheA['test1'], - $cacheA['test2'], - $cacheB['test1'], - $cacheB['test2'], + $cacheA->load('test1'), + $cacheA->load('test2'), + $cacheB->load('test1'), + $cacheB->load('test2'), ))); $storage->clean(array(Cache::ALL => TRUE)); -Assert::null( $cacheA['test1'] ); - -Assert::null( $cacheA['test2'] ); - -Assert::null( $cacheB['test1'] ); - -Assert::null( $cacheB['test2'] ); +Assert::null( $cacheA->load('test1') ); +Assert::null( $cacheA->load('test2') ); +Assert::null( $cacheB->load('test1') ); +Assert::null( $cacheB->load('test2') ); diff --git a/tests/Caching/FileStorage.closure.phpt b/tests/Caching/FileStorage.closure.phpt index 14a08735..466be746 100644 --- a/tests/Caching/FileStorage.closure.phpt +++ b/tests/Caching/FileStorage.closure.phpt @@ -18,7 +18,7 @@ $value = range("\x00", "\xFF"); $cache = new Cache(new FileStorage(TEMP_DIR)); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache using Closure... @@ -36,4 +36,4 @@ $cache->save($key, function() { return NULL; }); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.const.001.phpt b/tests/Caching/FileStorage.const.001.phpt index 4c474878..a54d163e 100644 --- a/tests/Caching/FileStorage.const.001.phpt +++ b/tests/Caching/FileStorage.const.001.phpt @@ -26,4 +26,4 @@ $cache->save($key, $value, array( Cache::CONSTS => 'ANY_CONST', )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.const.002.phpt b/tests/Caching/FileStorage.const.002.phpt index ef788717..08f0ac86 100644 --- a/tests/Caching/FileStorage.const.002.phpt +++ b/tests/Caching/FileStorage.const.002.phpt @@ -21,4 +21,4 @@ $cache = new Cache(new FileStorage(TEMP_DIR)); // Deleting dependent const -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.expiration.phpt b/tests/Caching/FileStorage.expiration.phpt index 566159d9..ac6b808f 100644 --- a/tests/Caching/FileStorage.expiration.phpt +++ b/tests/Caching/FileStorage.expiration.phpt @@ -27,10 +27,10 @@ $cache->save($key, $value, array( // Sleeping 1 second sleep(1); clearstatcache(); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Sleeping 3 seconds sleep(3); clearstatcache(); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.files.phpt b/tests/Caching/FileStorage.files.phpt index 68522f77..64685a01 100644 --- a/tests/Caching/FileStorage.files.phpt +++ b/tests/Caching/FileStorage.files.phpt @@ -29,13 +29,13 @@ $cache->save($key, $value, array( ), )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Modifing dependent file file_put_contents($dependentFile, 'a'); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache... @@ -43,7 +43,7 @@ $cache->save($key, $value, array( Cache::FILES => $dependentFile, )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Modifing dependent file @@ -51,4 +51,4 @@ sleep(2); file_put_contents($dependentFile, 'b'); clearstatcache(); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.int.phpt b/tests/Caching/FileStorage.int.phpt index a5130ac1..75661981 100644 --- a/tests/Caching/FileStorage.int.phpt +++ b/tests/Caching/FileStorage.int.phpt @@ -18,27 +18,23 @@ $value = range("\x00", "\xFF"); $cache = new Cache(new FileStorage(TEMP_DIR)); -Assert::false( isset($cache[$key]) ); - -Assert::null( $cache[$key] ); +Assert::null( $cache->load($key) ); // Writing cache... -$cache[$key] = $value; - -Assert::true( isset($cache[$key]) ); +$cache->save($key, $value); -Assert::same( $cache[$key], $value ); +Assert::same( $cache->load($key), $value ); -// Removing from cache using unset()... -unset($cache[$key]); +// Removing from cache using remove()... +$cache->remove($key); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Removing from cache using set NULL... -$cache[$key] = $value; -$cache[$key] = NULL; +$cache->save($key, $value); +$cache->save($key, NULL); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.items.phpt b/tests/Caching/FileStorage.items.phpt index 33ce9993..80cfb05d 100644 --- a/tests/Caching/FileStorage.items.phpt +++ b/tests/Caching/FileStorage.items.phpt @@ -23,13 +23,13 @@ $cache->save($key, $value, array( Cache::ITEMS => array('dependent'), )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Modifing dependent cached item -$cache['dependent'] = 'hello world'; +$cache->save('dependent', 'hello world'); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache... @@ -37,14 +37,14 @@ $cache->save($key, $value, array( Cache::ITEMS => 'dependent', )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Modifing dependent cached item sleep(2); -$cache['dependent'] = 'hello europe'; +$cache->save('dependent', 'hello europe'); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache... @@ -52,10 +52,10 @@ $cache->save($key, $value, array( Cache::ITEMS => 'dependent', )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Deleting dependent cached item -$cache['dependent'] = NULL; +$cache->save('dependent', NULL); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.loadOrSave.phpt b/tests/Caching/FileStorage.loadOrSave.phpt index 12fe58a6..9520dc56 100644 --- a/tests/Caching/FileStorage.loadOrSave.phpt +++ b/tests/Caching/FileStorage.loadOrSave.phpt @@ -18,7 +18,7 @@ $value = range("\x00", "\xFF"); $cache = new Cache(new FileStorage(TEMP_DIR)); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache using Closure... @@ -36,4 +36,4 @@ Assert::same( $cache->load($key), $value ); // Sleeping 3 seconds sleep(3); clearstatcache(); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.namespace.phpt b/tests/Caching/FileStorage.namespace.phpt index 35b32cc4..511ce828 100644 --- a/tests/Caching/FileStorage.namespace.phpt +++ b/tests/Caching/FileStorage.namespace.phpt @@ -18,17 +18,15 @@ $cacheB = new Cache($storage, 'b'); // Writing cache... -$cacheA['key'] = 'hello'; -$cacheB['key'] = 'world'; +$cacheA->save('key', 'hello'); +$cacheB->save('key', 'world'); -Assert::true( isset($cacheA['key']) ); -Assert::true( isset($cacheB['key']) ); -Assert::same( $cacheA['key'], 'hello' ); -Assert::same( $cacheB['key'], 'world' ); +Assert::same( $cacheA->load('key'), 'hello' ); +Assert::same( $cacheB->load('key'), 'world' ); -// Removing from cache #2 using unset()... -unset($cacheB['key']); +// Removing from cache #2 using remove()... +$cacheB->remove('key'); -Assert::true( isset($cacheA['key']) ); -Assert::false( isset($cacheB['key']) ); +Assert::truthy( $cacheA->load('key') ); +Assert::null( $cacheB->load('key') ); diff --git a/tests/Caching/FileStorage.priority.phpt b/tests/Caching/FileStorage.priority.phpt index 7fb937f2..23b4f688 100644 --- a/tests/Caching/FileStorage.priority.phpt +++ b/tests/Caching/FileStorage.priority.phpt @@ -30,7 +30,7 @@ $cache->save('key3', 'value3', array( Cache::PRIORITY => 300, )); -$cache['key4'] = 'value4'; +$cache->save('key4', 'value4'); // Cleaning by priority... @@ -38,7 +38,7 @@ $cache->clean(array( Cache::PRIORITY => '200', )); -Assert::false( isset($cache['key1']) ); -Assert::false( isset($cache['key2']) ); -Assert::true( isset($cache['key3']) ); -Assert::true( isset($cache['key4']) ); +Assert::null( $cache->load('key1') ); +Assert::null( $cache->load('key2') ); +Assert::truthy( $cache->load('key3') ); +Assert::truthy( $cache->load('key4') ); diff --git a/tests/Caching/FileStorage.sliding.phpt b/tests/Caching/FileStorage.sliding.phpt index 0b301f6b..4002c863 100644 --- a/tests/Caching/FileStorage.sliding.phpt +++ b/tests/Caching/FileStorage.sliding.phpt @@ -30,7 +30,7 @@ for ($i = 0; $i < 5; $i++) { sleep(1); clearstatcache(); - Assert::true( isset($cache[$key]) ); + Assert::truthy( $cache->load($key) ); } @@ -38,4 +38,4 @@ for ($i = 0; $i < 5; $i++) { sleep(5); clearstatcache(); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/FileStorage.tags.phpt b/tests/Caching/FileStorage.tags.phpt index 477154fd..b7774152 100644 --- a/tests/Caching/FileStorage.tags.phpt +++ b/tests/Caching/FileStorage.tags.phpt @@ -30,7 +30,7 @@ $cache->save('key3', 'value3', array( Cache::TAGS => array('two', 'three'), )); -$cache['key4'] = 'value4'; +$cache->save('key4', 'value4'); // Cleaning by tags... @@ -38,7 +38,7 @@ $cache->clean(array( Cache::TAGS => 'one', )); -Assert::false( isset($cache['key1']) ); -Assert::false( isset($cache['key2']) ); -Assert::true( isset($cache['key3']) ); -Assert::true( isset($cache['key4']) ); +Assert::null( $cache->load('key1') ); +Assert::null( $cache->load('key2') ); +Assert::truthy( $cache->load('key3') ); +Assert::truthy( $cache->load('key4') ); diff --git a/tests/Caching/FileStorage.wrap.phpt b/tests/Caching/FileStorage.wrap.phpt index a78c8272..f67042b2 100644 --- a/tests/Caching/FileStorage.wrap.phpt +++ b/tests/Caching/FileStorage.wrap.phpt @@ -18,6 +18,15 @@ function mockFunction($x, $y) return $x + $y; } +class Test +{ + function mockMethod($x, $y) + { + $GLOBALS['called'] = TRUE; + return $x + $y; + } +} + $cache = new Cache(new FileStorage(TEMP_DIR)); @@ -28,3 +37,13 @@ Assert::true( $called ); $called = FALSE; Assert::same( 55, call_user_func($cache->wrap('mockFunction'), 5, 50) ); Assert::false( $called ); + + +$called = FALSE; +$callback = array(new Test, 'mockMethod'); +Assert::same( 55, call_user_func($cache->wrap($callback), 5, 50) ); +Assert::true( $called ); + +$called = FALSE; +Assert::same( 55, call_user_func($cache->wrap($callback), 5, 50) ); +Assert::false( $called ); diff --git a/tests/Caching/Memcached.expiration.phpt b/tests/Caching/Memcached.expiration.phpt index 8a969c46..566b6cca 100644 --- a/tests/Caching/Memcached.expiration.phpt +++ b/tests/Caching/Memcached.expiration.phpt @@ -31,9 +31,9 @@ $cache->save($key, $value, array( // Sleeping 1 second sleep(1); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Sleeping 3 seconds sleep(3); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/Memcached.files.phpt b/tests/Caching/Memcached.files.phpt index 961cedaa..37ea8125 100644 --- a/tests/Caching/Memcached.files.phpt +++ b/tests/Caching/Memcached.files.phpt @@ -34,13 +34,13 @@ $cache->save($key, $value, array( ), )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Modifing dependent file file_put_contents($dependentFile, 'a'); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache... @@ -48,7 +48,7 @@ $cache->save($key, $value, array( Cache::FILES => $dependentFile, )); -Assert::true( isset($cache[$key]) ); +Assert::truthy( $cache->load($key) ); // Modifing dependent file @@ -56,4 +56,4 @@ sleep(2); file_put_contents($dependentFile, 'b'); clearstatcache(); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/Memcached.priority.phpt b/tests/Caching/Memcached.priority.phpt index 4e819ef3..2f5e005f 100644 --- a/tests/Caching/Memcached.priority.phpt +++ b/tests/Caching/Memcached.priority.phpt @@ -35,7 +35,7 @@ $cache->save('nette-priority-key3', 'value3', array( Cache::PRIORITY => 300, )); -$cache['nette-priority-key4'] = 'value4'; +$cache->save('nette-priority-key4', 'value4'); // Cleaning by priority... @@ -43,7 +43,7 @@ $cache->clean(array( Cache::PRIORITY => '200', )); -Assert::false( isset($cache['nette-priority-key1']) ); -Assert::false( isset($cache['nette-priority-key2']) ); -Assert::true( isset($cache['nette-priority-key3']) ); -Assert::true( isset($cache['nette-priority-key4']) ); +Assert::null( $cache->load('nette-priority-key1') ); +Assert::null( $cache->load('nette-priority-key2') ); +Assert::truthy( $cache->load('nette-priority-key3') ); +Assert::truthy( $cache->load('nette-priority-key4') ); diff --git a/tests/Caching/Memcached.sliding.phpt b/tests/Caching/Memcached.sliding.phpt index fd5e7c1a..c6c56a88 100644 --- a/tests/Caching/Memcached.sliding.phpt +++ b/tests/Caching/Memcached.sliding.phpt @@ -34,11 +34,11 @@ for ($i = 0; $i < 5; $i++) { // Sleeping 1 second sleep(1); - Assert::true( isset($cache[$key]) ); + Assert::truthy( $cache->load($key) ); } // Sleeping few seconds... sleep(5); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); diff --git a/tests/Caching/Memcached.tags.phpt b/tests/Caching/Memcached.tags.phpt index 3d160a16..c1377165 100644 --- a/tests/Caching/Memcached.tags.phpt +++ b/tests/Caching/Memcached.tags.phpt @@ -35,7 +35,7 @@ $cache->save('nette-tags-key3', 'value3', array( Cache::TAGS => array('two', 'three'), )); -$cache['nette-tags-key4'] = 'value4'; +$cache->save('nette-tags-key4', 'value4'); // Cleaning by tags... @@ -43,7 +43,7 @@ $cache->clean(array( Cache::TAGS => 'one', )); -Assert::false( isset($cache['nette-tags-key1']) ); -Assert::false( isset($cache['nette-tags-key2']) ); -Assert::true( isset($cache['nette-tags-key3']) ); -Assert::true( isset($cache['nette-tags-key4']) ); +Assert::null( $cache->load('nette-tags-key1') ); +Assert::null( $cache->load('nette-tags-key2') ); +Assert::truthy( $cache->load('nette-tags-key3') ); +Assert::truthy( $cache->load('nette-tags-key4') ); diff --git a/tests/Caching/SQLiteStorage.basic.phpt b/tests/Caching/SQLiteStorage.basic.phpt index 19bfca59..f8ff6b2d 100644 --- a/tests/Caching/SQLiteStorage.basic.phpt +++ b/tests/Caching/SQLiteStorage.basic.phpt @@ -23,31 +23,26 @@ $value = range("\x00", "\xFF"); $cache = new Cache(new SQLiteStorage(TEMP_DIR . '/db.db3')); -Assert::false( isset($cache[$key]) ); - -Assert::null( $cache[$key] ); +Assert::null( $cache->load($key) ); // Writing cache... -$cache[$key] = $value; - - -Assert::true( isset($cache[$key]) ); +$cache->save($key, $value); -Assert::same( $cache[$key], $value ); +Assert::same( $cache->load($key), $value ); -// Removing from cache using unset()... -unset($cache[$key]); +// Removing from cache using remove()... +$cache->remove($key); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Removing from cache using set NULL... -$cache[$key] = $value; -$cache[$key] = NULL; +$cache->save($key, $value); +$cache->save($key, NULL); -Assert::false( isset($cache[$key]) ); +Assert::null( $cache->load($key) ); // Writing cache... diff --git a/tests/Caching/SQLiteStorage.tags.phpt b/tests/Caching/SQLiteStorage.tags.phpt index 7639a138..43c59f05 100644 --- a/tests/Caching/SQLiteStorage.tags.phpt +++ b/tests/Caching/SQLiteStorage.tags.phpt @@ -33,7 +33,7 @@ $cache->save('key3', 'value3', array( Cache::TAGS => array('two', 'three'), )); -$cache['key4'] = 'value4'; +$cache->save('key4', 'value4'); // Cleaning by tags... @@ -41,7 +41,7 @@ $cache->clean(array( Cache::TAGS => array('one', 'xx'), )); -Assert::false( isset($cache['key1']) ); -Assert::false( isset($cache['key2']) ); -Assert::true( isset($cache['key3']) ); -Assert::true( isset($cache['key4']) ); +Assert::null( $cache->load('key1') ); +Assert::null( $cache->load('key2') ); +Assert::truthy( $cache->load('key3') ); +Assert::truthy( $cache->load('key4') );