Magento extension development - testing multiple c

2019-08-10 14:59发布

问题:

I am writing a test framework for a Magento extension I'm building. The extension has a lot of configuration values stored in etc/config.xml under <global><default>. The test framework instantiates an extension model and runs one of its methods. However, first it copies a config.xml file to /etc/config.xml. The idea is that the model is instantiated with a different config.xml every time, to test various configurations. The test framework loops through half a dozen different config.xml files.

The problem - even if I re-bootstrap Magento, the extension model always instantiates with the config.xml data from whatever file was present when the routine was started. I can see that the etc/config.xml file is indeed being changed on every iteration, and the changes show up in the global config when I do Mage::getConfig()->loadModulesConfiguration->getNode('default/module_name'). It's like the extension is caching its config values on a per-run basis. I'm executing the test file via PHP CLI.

Does anyone have any ideas on this one? I'm stumped. Thanks for reading.

回答1:

So I figured out a workaround, but I'm still not sure what's causing the behavior. In the model that I'm testing

$this->config = Mage::getStoreConfig('jd_premier/default');

returns the same (cached?) config data after I re-init Magento and call Mage::getConfig->reinit(). However,

$this->config = Mage::getConfig()->loadModulesConfiguration('config.xml')
                ->getNode('default/jd_premier/default');

returns the correct data from the newest version of config.xml.

No idea what's going on here, so if you can enlighten me I'm glad to accept it as the answer.