mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing issue where CakeTestCase would erase custom bootstrapped paths in tearDown().
Adding App::paths() to simplify getting all the paths App knows about. Fixes #1934
This commit is contained in:
parent
0e85170f28
commit
3a8b344208
4 changed files with 52 additions and 5 deletions
|
@ -227,6 +227,17 @@ class App {
|
|||
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
|
||||
|
|
|
@ -749,4 +749,16 @@ class AppTest extends CakeTestCase {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->_debug = Configure::read('debug');
|
||||
parent::setUp();
|
||||
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
Configure::write('debug', $this->_debug);
|
||||
parent::tearDown();
|
||||
unset($this->Result);
|
||||
unset($this->Reporter);
|
||||
}
|
||||
|
@ -230,4 +230,14 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
App::build();
|
||||
App::build($this->_pathRestore, App::RESET);
|
||||
if (class_exists('ClassRegistry', false)) {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue