I am having similar problem as this stackexchange post. I have looked that the database table core_config_data contains the value i need to retrieve. But $configValue=$this->_scopeConfig->getValue(path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) query returns null. (The error outputs while running unit test "Failed asserting that null matches expected".) I have tried the module code in Magento 2.1.0 and 2.0.7 versions getting same results.

I am suspecting that the problem might be in some missing etc file in my module or settings that is needed to retrieve db value in module?

My etc contains: module.xml, adminhtml/routes.xml and adminhtml/system.xml. Also system.xml:

   <field id="username" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">

SQL query: SELECT * FROM core_config_data a WHERE a.'path' LIKE '%eepohs_erply/account/username%' sql query

  • You tried a raw sql to check your value: SELECT * FROM core_config_data a WHERE a.path LIKE '%path/value/need%' Jul 24 '16 at 2:07
  • In your case, you can get the config value: $this->_scopeConfig->getValue('eepohs_erply/account/username'). Because, the scope is default and scope_id is equal to 0. Jul 24 '16 at 3:26
  • I have tried it and same result like described in question. Jul 24 '16 at 3:34
  • Tried to clear your Magento Cache? Jul 24 '16 at 3:36
  • I have tried it and same result like described in question. Jul 24 '16 at 8:14

core_config_data is null because in unit test you use the Mock object not the real one.

For example:

 $this->_scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');

If you want it return the value you must add this in your unit test:


For the real data test: I suggest you use integration test with a test database. So you can play with real data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.