Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit 8674636

Browse files
committed
Merge pull request #184 from AOEmedia/issue/178-fixture_scope
Issue/178 fixture scope
2 parents 9742b6a + b18329d commit 8674636

File tree

1 file changed

+18
-34
lines changed
  • app/code/community/EcomDev/PHPUnit/Model

1 file changed

+18
-34
lines changed

app/code/community/EcomDev/PHPUnit/Model/App.php

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
5959
const XML_PATH_CONTROLLER_RESPONSE = 'phpunit/suite/controller/response/class';
6060

6161
/**
62-
* Old configuration model to be returned back
63-
* after unit tests are finished
64-
*
65-
* @var Mage_Core_Model_Config
66-
*/
67-
protected static $_oldConfig = null;
68-
69-
/**
70-
* Old application model to be returned back
71-
* after unit tests are finished
72-
*
73-
* @var Mage_Core_Model_App
74-
*/
75-
protected static $_oldApplication = null;
76-
77-
/**
78-
* Old event collection to be returned back
79-
* after the unit tests are finished
80-
*
81-
* @var Varien_Event_Collection
82-
*/
83-
protected static $_oldEventCollection = null;
84-
85-
/**
86-
* List of singletons in original application
62+
* Test scope data to be returned back after unit tests are finished
8763
*
8864
* @var array
8965
*/
90-
protected static $_oldRegistry = null;
66+
protected static $_testScopeStack = array();
9167

9268
/**
9369
* Configuration model class name for unit tests
@@ -143,10 +119,12 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
143119
public static function applyTestScope()
144120
{
145121
// Save old environment variables
146-
self::$_oldApplication = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_app');
147-
self::$_oldConfig = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_config');
148-
self::$_oldEventCollection = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_events');
149-
self::$_oldRegistry = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_registry');
122+
self::$_testScopeStack[] = array(
123+
'app' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_app'),
124+
'config' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_config'),
125+
'events' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_events'),
126+
'registry' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_registry'),
127+
);
150128

151129

152130
// Setting environment variables for unit tests
@@ -434,11 +412,17 @@ protected function _initStores()
434412
*/
435413
public static function discardTestScope()
436414
{
415+
if(empty(self::$_testScopeStack)) {
416+
throw new RuntimeException('No test scope to discard');
417+
}
418+
419+
$previousScope = array_pop(self::$_testScopeStack);
420+
437421
// Setting environment variables for unit tests
438-
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_app', self::$_oldApplication);
439-
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_config', self::$_oldConfig);
440-
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_events', self::$_oldEventCollection);
441-
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_registry', self::$_oldRegistry);
422+
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_app', $previousScope['app']);
423+
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_config', $previousScope['config']);
424+
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_events', $previousScope['events']);
425+
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_registry', $previousScope['registry']);
442426
}
443427

444428
/**

0 commit comments

Comments
 (0)