How do you test setting and getting a session variable in PHPUnit/EComDev? This is what I've so far in my test method:
$checkoutSession = $this->getModelMock('checkout/session');
$checkoutSession->expects($this->any())->method('getData')->with('number')->will($this->returnCallback(array($this, 'getNumber')));
$checkoutSession->expects($this->any())->method('setData')->will($this->returnCallback(array($this, 'setNumber')));
In the test class, I've defined the following:
protected $_number = 5;
public function getNumber()
{
return $this->_number;
}
public function setNumber()
{
$args = func_get_args();
$key = $args[0];
$value = $args[1];
$this->_number = $value;
}
This works in the code being tested:
$checkoutSession = Mage::getSingleton('checkout/session');
$number = $checkoutSession->getData('number'); //5
$checkoutSession->setData('number', $number+1);
$number2 = $checkoutSession->getData('number'); //6
However, getting the variable with Magento's magic method does not:
$number = Mage::getSingleton('checkout/session')->getNumber();//this is null
How does one mock Magento's magic methods?