Skip to content

Commit

Permalink
Fixing issue where CakeTestCase would erase custom bootstrapped paths…
Browse files Browse the repository at this point in the history
… in tearDown().

Adding App::paths() to simplify getting all the paths App knows about.
Fixes #1934
  • Loading branch information
markstory committed Aug 30, 2011
1 parent 0e85170 commit 3a8b344
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
11 changes: 11 additions & 0 deletions lib/Cake/Core/App.php
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/Core/AppTest.php
Expand Up @@ -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);
}
}
14 changes: 12 additions & 2 deletions lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
Expand Up @@ -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');
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
20 changes: 17 additions & 3 deletions lib/Cake/TestSuite/CakeTestCase.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 3a8b344

Please sign in to comment.