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 MyCompany_MyModule_Index_IndexController $indexController */ $indexController = Mage::getControllerInstance('mycompany_mymodule/index_index') return $indexController; } }
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::getControllerInstance() method with the correct key $controller = $this->buildMock('MyCompany_MyModule_Index_IndexController'); $this->addMageControllerInstance('mycompany_mymodule/index_index', $controller); $result = $this->_instance->doSomething(); $this->assertSame($controller, $result); } }