Now days I am focusing on TDD development, and I am following the Magento
test class for reference. So firstly I look into Contact
module (as it is the small module) and I found that in DataTest.php
from Magento\Contact\Test\Unit\Helper\DataTest.php
it gets the mock object from construct
argument. like in setUp
you can find it like,
protected function setUp()
{
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$className = \Magento\Contact\Helper\Data::class;
$arguments = $this->objectManagerHelper->getConstructArguments($className);
/**
* @var \Magento\Framework\App\Helper\Context $context
*/
$context = $arguments['context'];
$this->scopeConfigMock = $context->getScopeConfig();
$this->customerSessionMock = $arguments['customerSession'];
$this->customerViewHelperMock = $arguments['customerViewHelper'];
$this->helper = $this->objectManagerHelper->getObject($className, $arguments);
}
from here customersession
Magento
get the mock object from construct argument.
`$this->customerSessionMock = $arguments['customerSession'];`
But in some of test class magento
create the mock object by using createMock
method. Like,
$this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
So which way I should follow to create mock
object ? and why?