I found a strange problem while doing some unit-testing on Magento.
I have a test function which test a value from core_config_data table. So in order to have access to that value for test, in the setUp() function I am saving the config value in database:
public function setUp()
{
parent::setUp();
$systemConfig = new Mage_Core_Model_Config();
$systemConfig->saveConfig(
'my/custom/path/config',
12
);
}
and in my test method I am getting that value from database likeso:
$productsNo = Mage::getStoreConfig(my/custom/path/config);
but its value is null, and not a string as expected.
This is strange, because if I am refreshing the database after running the test, the value it’s existing in database. And if I’m running the test again, the test will work and the value it’s not null anymore.
What am I doing wrong? I don’t save the value correctly, or I don’t fetch it in a good way?
You only save the configuration value to the database, but you don’t refresh the config cache, which is used by
Mage::getStoreConfig().To achieve saving and refreshing at the same time you could use:
This way the configuration value will be available in the current and subsequent requests.
In case you don’t really need persistence, that is, if you only need this configuration value for the current request, than I’d rather recommend to use: