There was an error while loading. Please reload this page.
Code you want to test
<?php class MyCompany_MyModule_Model_Example_Mocking { public function doSomething() { /** @var Mage_Sales_Model_Order $order */ $order = Mage::getModel('sales/order'); $order->save(); } }
Test implementation
<?php class MyCompany_MyModule_Unit_Model_Example_MockingTest extends TechDivision_MagentoUnitTesting_TestCase_Model { /** * @var string */ protected $_testClassName = 'MyCompany_MyModule_Model_Example_Mocking'; /** * @var MyCompany_MyModule_Model_Example_Mocking */ protected $_instance; public function testDoSomething() { // Build a mock object and register it for the // Mage::getModel() method with the correct key $order = $this->buildMock('Mage_Sales_Model_Order'); $this->addMageModel('sales/order', $order); // Method 'save' must be invoked one time $order->expects($this->once()) ->method('save'); // Execute 'doSomething' method $this->_instance->doSomething(); } }