@@ -59,35 +59,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
59
59
const XML_PATH_CONTROLLER_RESPONSE = 'phpunit/suite/controller/response/class ' ;
60
60
61
61
/**
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
87
63
*
88
64
* @var array
89
65
*/
90
- protected static $ _oldRegistry = null ;
66
+ protected static $ _testScopeStack = array () ;
91
67
92
68
/**
93
69
* Configuration model class name for unit tests
@@ -143,10 +119,12 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
143
119
public static function applyTestScope ()
144
120
{
145
121
// 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
+ );
150
128
151
129
152
130
// Setting environment variables for unit tests
@@ -434,11 +412,17 @@ protected function _initStores()
434
412
*/
435
413
public static function discardTestScope ()
436
414
{
415
+ if (empty (self ::$ _testScopeStack )) {
416
+ throw new RuntimeException ('No test scope to discard ' );
417
+ }
418
+
419
+ $ previousScope = array_pop (self ::$ _testScopeStack );
420
+
437
421
// 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 ' ] );
442
426
}
443
427
444
428
/**
0 commit comments