diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index d36ff7966ef..9a9f178873f 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -227,6 +227,17 @@ public static function path($type, $plugin = null) { return self::$_packages[$type]; } +/** + * Get all the currently loaded paths from App. Useful for inspecting + * or storing all paths App knows about. For a paths to a specific package + * use App::path() + * + * @return array An array of packages and their associated paths. + */ + public static function paths() { + return self::$_packages; + } + /** * Sets up each package location on the file system. You can configure multiple search paths * for each package, those will be used to look for files one folder at a time in the specified order diff --git a/lib/Cake/Test/Case/Core/AppTest.php b/lib/Cake/Test/Case/Core/AppTest.php index 945a760621e..59a90edb52e 100644 --- a/lib/Cake/Test/Case/Core/AppTest.php +++ b/lib/Cake/Test/Case/Core/AppTest.php @@ -749,4 +749,16 @@ public function testClassLocation() { App::uses('MyCustomClass', 'MyPackage/Name'); $this->assertEquals('MyPackage/Name', App::location('MyCustomClass')); } + +/** + * Test that paths() works. + * + * @return void + */ + public function testPaths() { + $result = App::paths(); + $this->assertArrayHasKey('plugins', $result); + $this->assertArrayHasKey('Controller', $result); + $this->assertArrayHasKey('Controller/Component', $result); + } } diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php index 07b855d6cff..5ed8b2a44f9 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php @@ -46,7 +46,7 @@ public static function setUpBeforeClass() { * @return void */ public function setUp() { - $this->_debug = Configure::read('debug'); + parent::setUp(); $this->Reporter = $this->getMock('CakeHtmlReporter'); } @@ -56,7 +56,7 @@ public function setUp() { * @return void */ public function tearDown() { - Configure::write('debug', $this->_debug); + parent::tearDown(); unset($this->Result); unset($this->Reporter); } @@ -230,4 +230,14 @@ public function testSkipIf() { $result = $test->run(); $this->assertEquals(0, $result->skippedCount()); } + +/** + * Test that CakeTestCase::setUp() backs up values. + * + * @return void + */ + public function testSetupBackUpValues() { + $this->assertArrayHasKey('debug', $this->_configure); + $this->assertArrayHasKey('plugins', $this->_pathRestore); + } } diff --git a/lib/Cake/TestSuite/CakeTestCase.php b/lib/Cake/TestSuite/CakeTestCase.php index 082c3bd509b..e986abb0811 100644 --- a/lib/Cake/TestSuite/CakeTestCase.php +++ b/lib/Cake/TestSuite/CakeTestCase.php @@ -58,6 +58,12 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase { */ protected $_configure = array(); +/** + * Path settings to restore at the end of the test. + * + * @var array + */ + protected $_pathRestore = array(); /** * Runs the test case and collects the results in a TestResult object. @@ -112,13 +118,21 @@ public function skipIf($shouldSkip, $message = '') { } /** - * setup the test case, backup the static object values so they can be restored. + * Setup the test case, backup the static object values so they can be restored. + * Specifically backs up the contents of Configure and paths in App if they have + * not already been backed up. * * @return void */ public function setUp() { parent::setUp(); - $this->_configure = Configure::read(); + + if (empty($this->_configure)) { + $this->_configure = Configure::read(); + } + if (empty($this->_pathRestore)) { + $this->_pathRestore = App::paths(); + } if (class_exists('Router', false)) { Router::reload(); } @@ -131,7 +145,7 @@ public function setUp() { */ public function tearDown() { parent::tearDown(); - App::build(); + App::build($this->_pathRestore, App::RESET); if (class_exists('ClassRegistry', false)) { ClassRegistry::flush(); }