We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit d77b04cd authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

+ New feature #12: Support annotations per test function/class to enable/disable cache

parent 1260662b
...@@ -179,15 +179,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App ...@@ -179,15 +179,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
// Set using cache // Set using cache
// for things that shouldn't be reloaded each time // for things that shouldn't be reloaded each time
EcomDev_Utils_Reflection::setRestrictedPropertyValue( $this->setCacheOptions(array(
$this->_cache, 'eav' => 1,
'_allowedCacheOptions', 'layout' => 1,
array( 'translate' => 1
'eav' => 1, ));
'layout' => 1,
'translate' => 1
)
);
// Clean cache before the whole suite is running // Clean cache before the whole suite is running
$this->getCache()->clean(); $this->getCache()->clean();
...@@ -227,7 +223,35 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App ...@@ -227,7 +223,35 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
$this->replaceRegistry(self::REGISTRY_PATH_SHARED_STORAGE, new Varien_Object()); $this->replaceRegistry(self::REGISTRY_PATH_SHARED_STORAGE, new Varien_Object());
return $this; return $this;
} }
/**
* Sets cache options for test case
*
* @param array $options
* @return EcomDev_PHPUnit_Model_App
*/
public function setCacheOptions(array $options)
{
EcomDev_Utils_Reflection::setRestrictedPropertyValue(
$this->_cache,
'_allowedCacheOptions',
$options
);
}
/**
* Retrieve cache options for test case
*
* @return array
*/
public function getCacheOptions()
{
return EcomDev_Utils_Reflection::getRestrictedPropertyValue(
$this->_cache,
'_allowedCacheOptions'
);
}
/** /**
* Retrieves a model from config and checks it on interface implementation * Retrieves a model from config and checks it on interface implementation
* *
......
...@@ -51,6 +51,9 @@ class EcomDev_PHPUnit_Model_Fixture ...@@ -51,6 +51,9 @@ class EcomDev_PHPUnit_Model_Fixture
// Key for loaded entities by EAV loaders // Key for loaded entities by EAV loaders
const STORAGE_KEY_ENTITIES = 'entities'; const STORAGE_KEY_ENTITIES = 'entities';
// Key for loaded cache options
const STORAGE_KEY_CACHE_OPTIONS = 'cache_options';
// Key for created scope models // Key for created scope models
const STORAGE_KEY_SCOPE = 'scope'; const STORAGE_KEY_SCOPE = 'scope';
...@@ -275,6 +278,11 @@ class EcomDev_PHPUnit_Model_Fixture ...@@ -275,6 +278,11 @@ class EcomDev_PHPUnit_Model_Fixture
'loadFixture', 'loadFixture',
array('class', 'method') array('class', 'method')
); );
$cacheOptions = $testCase->getAnnotationByName('cache', 'method');
$this->_parseCacheOptions($cacheOptions);
$this->_loadFixtureFiles($fixtures, $testCase); $this->_loadFixtureFiles($fixtures, $testCase);
...@@ -301,9 +309,42 @@ class EcomDev_PHPUnit_Model_Fixture ...@@ -301,9 +309,42 @@ class EcomDev_PHPUnit_Model_Fixture
null, array($className, 'loadSharedFixture', 'class') null, array($className, 'loadSharedFixture', 'class')
); );
$cacheOptions = $method->invokeArgs(
null, array($className, 'cache', 'class')
);
$this->_parseCacheOptions($cacheOptions);
$this->_loadFixtureFiles($fixtures, $className); $this->_loadFixtureFiles($fixtures, $className);
return $this; return $this;
} }
/**
* Loads test case cache on off annotations
*
* @param array $annotations
* @return EcomDev_PHPUnit_Model_Fixture
*/
protected function _parseCacheOptions($annotations)
{
$cacheOptions = array();
foreach ($annotations as $annotation) {
list($action, $cacheType) = preg_split('/\s+/', trim($annotation));
$flag = ($action === 'off' ? 0 : 1);
if ($cacheType === 'all') {
foreach (Mage::app()->getCacheInstance()->getTypes() as $type) {
$cacheOptions[$type->getId()] = $flag;
}
} else {
$cacheOptions[$cacheType] = $flag;
}
}
if ($cacheOptions) {
$this->_fixture['cache_options'] = $cacheOptions;
}
}
/** /**
* Loads fixture files * Loads fixture files
...@@ -411,6 +452,36 @@ class EcomDev_PHPUnit_Model_Fixture ...@@ -411,6 +452,36 @@ class EcomDev_PHPUnit_Model_Fixture
$this->_fixture = array(); $this->_fixture = array();
} }
/**
* Applies cache options for current test or test case
*
* @param array $options
* @return EcomDev_PHPUnit_Model_Fixture
*/
protected function _applyCacheOptions($options)
{
$originalOptions = Mage::app()->getCacheOptions();
$this->setStorageData(self::STORAGE_KEY_CACHE_OPTIONS, $originalOptions);
$options += $originalOptions;
Mage::app()->setCacheOptions($options);
return $this;
}
/**
* Discards changes that were made to Magento cache
*
* @return EcomDev_PHPUnit_Model_Fixture
*/
protected function _discardCacheOptions()
{
Mage::app()->setCacheOptions(
$this->getStorageData(self::STORAGE_KEY_CACHE_OPTIONS)
);
return $this;
}
/** /**
* Applies fixture configuration values into Mage_Core_Model_Config * Applies fixture configuration values into Mage_Core_Model_Config
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment