Following is the Unit Test error that I get
Expectation failed for method name is equal to when invoked zero or more times Parameter 0 for invocation Magento\Framework\App\Config\ScopeConfigInterface::getValue('module/general/base_url', 'store', null) does not match expected value. 'custom/general/base_url' does not match expected type "array".
My test code is as below
<?php
namespace Custom\Module\Test\Unit\Helper;
class ConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Custom\Module\Helper\Config
*/
protected $configHelper;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
*/
protected function setUp()
{
$methods = array_merge(
get_class_methods(\Magento\Framework\App\Config\ScopeConfigInterface::class)
);
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
->setMethods($methods)
->disableOriginalConstructor()
->getMock();
$this->scopeConfig->method('getValue')
->with([
'module/general/base_url',
'module/general/user',
'module/general/api_user',
'module/general/api_password'
])
->willReturnMap([
['base_url', 'http://domain.com/'],
['user', 'User'],
['api_user', '[email protected]'],
['api_password', 'ynY6rdZ3EDd3']
]);
$context = $this->getMockBuilder(\Magento\Framework\App\Helper\Context::class)
->disableOriginalConstructor()
->getMock();
$this->configHelper = new \Custom\Module\Helper\Config($context, $this->storeManager, $this->scopeConfig);
}
public function testBaseUrl()
{
$defaultValue = 'http://domain.com/';
$this->assertEquals($defaultValue, $this->configHelper->getUser());
}
public function testConfiguratorScriptUrl()
{
$defaultValue = 'http://domain.com/Theme/User/Content/Scripts/Configurator/configurator.js';
$this->assertEquals($defaultValue, $this->configHelper->getConfiguratorScriptUrl());
}
}
I have gone through many other examples on the website with single stud method
and willReturn
value and that works. But I wanted to test multiple scope config values and based on my code my can't get the it working. I am not using any many methods here, both getBaseUrl()
and getConfiguratorScriptUrl()
are actual functions that I use to retrieve the values using helper.
Please guys let me know if you need any more details or any other part of the code that you think may be linked with it.