From fbf054b22b04e6d8205e3a523afa9d40c74981c7 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 22 Feb 2010 23:21:30 -0500 Subject: [PATCH] Making FileEngine emit errors when a path does not exist but is used for caching. Should make cryptic errors coming from Cache easier to figure out. Removed useless private property. Tests added. Fixes #384 --- cake/libs/cache/file.php | 24 +++++++---------------- cake/tests/cases/libs/cache/file.test.php | 18 +++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index 7241c864837..1907c84e9ed 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -19,6 +19,9 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +if (!class_exists('File')) { + require LIBS . 'file.php'; +} /** * File Storage engine for cache * @@ -50,14 +53,6 @@ class FileEngine extends CacheEngine { */ var $settings = array(); -/** - * Set to true if FileEngine::init(); and FileEngine::__active(); do not fail. - * - * @var boolean - * @access private - */ - var $__active = false; - /** * True unless FileEngine::__active(); fails * @@ -85,9 +80,6 @@ function init($settings = array()) { $settings )); if (!isset($this->__File)) { - if (!class_exists('File')) { - require LIBS . 'file.php'; - } $this->__File =& new File($this->settings['path'] . DS . 'cake'); } @@ -95,9 +87,9 @@ function init($settings = array()) { $this->settings['isWindows'] = true; } - $this->settings['path'] = $this->__File->Folder->cd($this->settings['path']); - if (empty($this->settings['path'])) { - return false; + $path = $this->__File->Folder->cd($this->settings['path']); + if ($path) { + $this->settings['path'] = $path; } return $this->__active(); } @@ -266,11 +258,9 @@ function __setKey($key) { * @access private */ function __active() { - if (!$this->__active && $this->__init && !is_writable($this->settings['path'])) { + if ($this->__init && !is_writable($this->settings['path'])) { $this->__init = false; trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING); - } else { - $this->__active = true; } return true; } diff --git a/cake/tests/cases/libs/cache/file.test.php b/cake/tests/cases/libs/cache/file.test.php index ad093787ca4..16a7bc705e2 100644 --- a/cake/tests/cases/libs/cache/file.test.php +++ b/cake/tests/cases/libs/cache/file.test.php @@ -355,5 +355,23 @@ function testWriteQuotedString() { Cache::write('App.singleQuoteTest', "'this is a quoted string'"); $this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'"); } + +/** + * check that FileEngine generates an error when a configured Path does not exist. + * + * @return void + */ + function testErrorWhenPathDoesNotExist() { + if ($this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists. %s')) { + return; + } + $this->expectError(); + Cache::config('failure', array( + 'engine' => 'File', + 'path' => TMP . 'tests' . DS . 'file_failure' + )); + + Cache::drop('failure'); + } } ?> \ No newline at end of file