From 0dec093f482e13413a034f20db7f99338952900e Mon Sep 17 00:00:00 2001 From: ber clausen Date: Fri, 10 Aug 2012 10:46:18 -0300 Subject: [PATCH] The actual config file must always have .php extension. --- lib/Cake/Configure/PhpReader.php | 9 +++---- .../Test/Case/Configure/PhpReaderTest.php | 25 +++++++++++++------ .../Test/test_app/Config/no_php_extension | 9 +++++++ 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 lib/Cake/Test/test_app/Config/no_php_extension diff --git a/lib/Cake/Configure/PhpReader.php b/lib/Cake/Configure/PhpReader.php index f5d96196135..1149a1f08e2 100644 --- a/lib/Cake/Configure/PhpReader.php +++ b/lib/Cake/Configure/PhpReader.php @@ -66,22 +66,21 @@ public function read($key) { $key = substr($key, 0, -4); } list($plugin, $key) = pluginSplit($key); + $key .= '.php'; if ($plugin) { $file = App::pluginPath($plugin) . 'Config' . DS . $key; } else { $file = $this->_path . $key; } - $file .= '.php'; if (!is_file($file)) { - if (!is_file(substr($file, 0, -4))) { - throw new ConfigureException(__d('cake_dev', 'Could not load configuration files: %s or %s', $file, substr($file, 0, -4))); - } + throw new ConfigureException(__d('cake_dev', 'Could not load configuration file: %s', $file)); } + include $file; if (!isset($config)) { throw new ConfigureException( - sprintf(__d('cake_dev', 'No variable $config found in %s.php'), $file) + sprintf(__d('cake_dev', 'No variable $config found in %s'), $file) ); } return $config; diff --git a/lib/Cake/Test/Case/Configure/PhpReaderTest.php b/lib/Cake/Test/Case/Configure/PhpReaderTest.php index 08982cb4ec1..98ae2e88ecf 100644 --- a/lib/Cake/Test/Case/Configure/PhpReaderTest.php +++ b/lib/Cake/Test/Case/Configure/PhpReaderTest.php @@ -41,7 +41,7 @@ class PhpReaderTest extends CakeTestCase { ); /** - * setup + * Setup. * * @return void */ @@ -51,7 +51,7 @@ public function setUp() { } /** - * test reading files + * Test reading files. * * @return void */ @@ -65,21 +65,32 @@ public function testRead() { $this->assertEquals('value', $values['Read']); } +/** + * Test an exception is thrown by reading files that exist without .php extension. + * + * @expectedException ConfigureException + * @return void + */ + public function testReadWithExistentFileWithoutExtension() { + $reader = new PhpReader($this->path); + $reader->read('no_php_extension'); + } + /** * Test an exception is thrown by reading files that don't exist. * * @expectedException ConfigureException * @return void */ - public function testReadWithNonExistantFile() { + public function testReadWithNonExistentFile() { $reader = new PhpReader($this->path); $reader->read('fake_values'); } /** - * test reading an empty file. + * Test reading an empty file. * - * @expectedException RuntimeException + * @expectedException ConfigureException * @return void */ public function testReadEmptyFile() { @@ -88,7 +99,7 @@ public function testReadEmptyFile() { } /** - * test reading keys with ../ doesn't work + * Test reading keys with ../ doesn't work. * * @expectedException ConfigureException * @return void @@ -99,7 +110,7 @@ public function testReadWithDots() { } /** - * test reading from plugins + * Test reading from plugins. * * @return void */ diff --git a/lib/Cake/Test/test_app/Config/no_php_extension b/lib/Cake/Test/test_app/Config/no_php_extension new file mode 100644 index 00000000000..d5e30ee329f --- /dev/null +++ b/lib/Cake/Test/test_app/Config/no_php_extension @@ -0,0 +1,9 @@ + array( + 'Third' => array( + 'ThirdDeepest' => 'buried3' + ) + ) +);