diff --git a/.travis.yml b/.travis.yml index 862337e3..143c75c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,9 @@ matrix: allow_failures: - php: hhvm -script: vendor/bin/tester tests -s -c tests/php-unix.ini +script: + - vendor/bin/tester tests -s -c tests/php-unix.ini + - php code-checker/src/code-checker.php -d src after_failure: # Print *.actual content @@ -20,5 +22,6 @@ services: - memcached before_script: - # Install Nette Tester + # 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 diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index 71721cd7..82113cda 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -149,7 +149,6 @@ private function completeDependencies($dp, $data) // convert FILES into CALLBACKS if (isset($dp[self::FILES])) { - //clearstatcache(); foreach (array_unique((array) $dp[self::FILES]) as $item) { $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item)); // @ - stat may fail } @@ -221,7 +220,7 @@ public function call($function) * Caches results of function/method calls. * @param mixed * @param array dependencies - * @return Closure + * @return \Closure */ public function wrap($function, array $dependencies = NULL) { @@ -268,11 +267,7 @@ protected function generateKey($key) /** - * Inserts (replaces) item into the cache (\ArrayAccess implementation). - * @param mixed key - * @param mixed - * @return void - * @throws Nette\InvalidArgumentException + * @deprecated */ public function offsetSet($key, $data) { @@ -281,10 +276,7 @@ public function offsetSet($key, $data) /** - * Retrieves the specified item from the cache or NULL if the key is not found (\ArrayAccess implementation). - * @param mixed key - * @return mixed|NULL - * @throws Nette\InvalidArgumentException + * @deprecated */ public function offsetGet($key) { @@ -298,10 +290,7 @@ public function offsetGet($key) /** - * Exists item in cache? (\ArrayAccess implementation). - * @param mixed key - * @return bool - * @throws Nette\InvalidArgumentException + * @deprecated */ public function offsetExists($key) { @@ -311,10 +300,7 @@ public function offsetExists($key) /** - * Removes the specified item from the cache. - * @param mixed key - * @return void - * @throws Nette\InvalidArgumentException + * @deprecated */ public function offsetUnset($key) { @@ -323,8 +309,7 @@ public function offsetUnset($key) /** - * Discards the internal cache used by ArrayAccess. - * @return void + * @deprecated */ public function release() { diff --git a/src/Caching/Storages/FileJournal.php b/src/Caching/Storages/FileJournal.php index 5cb805d1..89d9a6ee 100644 --- a/src/Caching/Storages/FileJournal.php +++ b/src/Caching/Storages/FileJournal.php @@ -804,7 +804,7 @@ private function findIndexNode($type, $search, $childId = NULL, $prevId = NULL) $nodeId = $node[$search]; } else { foreach ($node as $key => $childNode) { - if ($key > $search and $key !== self::INFO) { + if ($key > $search && $key !== self::INFO) { $nodeId = $childNode; continue 2; } diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 081a9193..451510e6 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -111,7 +111,7 @@ public function remove($key) public function clean(array $conditions) { if (!empty($conditions[Cache::ALL])) { - $this->pdo->prepare('DELETE FROM cache'); + $this->pdo->prepare('DELETE FROM cache')->execute(); } elseif (!empty($conditions[Cache::TAGS])) { $tags = (array) $conditions[Cache::TAGS]; diff --git a/tests/Caching/Cache.inc b/tests/Caching/Cache.inc new file mode 100644 index 00000000..6ffb2f99 --- /dev/null +++ b/tests/Caching/Cache.inc @@ -0,0 +1,27 @@ +data[$key]) ? $this->data[$key] : NULL; + } + + public function write($key, $data, array $dependencies) + { + $this->data[$key] = array( + 'data' => $data, + 'dependencies' => $dependencies, + ); + } + + public function lock($key) {} + + public function remove($key) {} + + public function clean(array $conditions) {} +} diff --git a/tests/Caching/Cache.load.phpt b/tests/Caching/Cache.load.phpt new file mode 100644 index 00000000..87411909 --- /dev/null +++ b/tests/Caching/Cache.load.phpt @@ -0,0 +1,46 @@ +load('key', function() { + return 'value'; +}); +Assert::equal('value', $value); + +$data = $cache->load('key', function() { + return "won't load this value"; // will read from storage +}); +Assert::equal('value', $data['data']); + + +// load twice with fallback, pass dependencies +$dependencies = array(Cache::TAGS => 'tag'); +$storage = new TestStorage(); +$cache = new Cache($storage, 'ns'); + +$value = $cache->load('key', function(& $deps) use ($dependencies) { + $deps = $dependencies; + return 'value'; +}); +Assert::equal('value', $value); + +$data = $cache->load('key', function() { + return "won't load this value"; // will read from storage +}); +Assert::equal('value', $data['data']); +Assert::equal($dependencies, $data['dependencies']); diff --git a/tests/Caching/Cache.save.phpt b/tests/Caching/Cache.save.phpt new file mode 100644 index 00000000..79828048 --- /dev/null +++ b/tests/Caching/Cache.save.phpt @@ -0,0 +1,49 @@ + 'tag'); + +$cache->save('key', 'value', $dependencies); + +Assert::equal('value', $cache['key']['data']); +Assert::equal($dependencies, $cache['key']['dependencies']); + + +// save callback return value +$storage = new testStorage(); +$cache = new Cache($storage, 'ns'); + +$cache->save('key', function() { + return 'value'; +}); + +Assert::equal('value', $cache['key']['data']); +Assert::equal(array(), $cache['key']['dependencies']); + + +// save callback return value with dependencies +$storage = new testStorage(); +$cache = new Cache($storage, 'ns'); +$dependencies = array(Cache::TAGS => 'tag'); + +$cache->save('key', function() { + return 'value'; +}, $dependencies); + +Assert::equal('value', $cache['key']['data']); +Assert::equal($dependencies, $cache['key']['dependencies']); diff --git a/tests/php-win.ini b/tests/php-win.ini index ebf6f1f7..e48a932b 100644 --- a/tests/php-win.ini +++ b/tests/php-win.ini @@ -1,5 +1,6 @@ [PHP] extension_dir = "./ext" +extension=php_mbstring.dll ;extension=php_memcache.dll [Zend]