1

I installed EcomDev_UnitTest as described in the readme.md

php ecomdev-phpunit.php -a magento-config --db-name mage_test --base-url http://localhost.foo/

And used this class to access adminhtml from the comments on the EcomDev_UnitTest blog:

<?php 

abstract class LeMike_DevMode_Test_Adminhtml extends EcomDev_PHPUnit_Test_Case_Controller
{
    const FAKE_USER_ID = 42;


    public function setUp()
    {
        $this->_fakeLogin();

        parent::setUp();
    }


    public function tearDown()
    {
        $adminSession = Mage::getSingleton('admin/session');
        $adminSession->unsetAll();
        $adminSession->getCookie()->delete($adminSession->getSessionName());
        parent::tearDown();
    }


    /**
     * Test whether fake user successfully logged in
     */
    public function testLoggedIn()
    {
        $this->assertTrue(Mage::getSingleton('admin/session')->isLoggedIn());
    }


    /**
     * Test whether logged user is fake
     */
    public function testLoggedUserIsFakeUser()
    {
        $this->assertEquals(Mage::getSingleton('admin/session')->getUser()->getId(), self::FAKE_USER_ID);
    }


    /**
     * Logged in to Magento with fake user to test an adminhtml controllers
     */
    protected function _fakeLogin()
    {
        $sessionMock = $this->getModelMockBuilder('admin/session')
                       ->disableOriginalConstructor()
                       ->setMethods(null)
                       ->getMock();
        $this->replaceByMock('singleton', 'admin/session', $sessionMock);

        $this->_registerUserMock();
        Mage::getSingleton('adminhtml/url')->turnOffSecretKey();
        $session = Mage::getSingleton('admin/session');
        $user    = $session->login('fakeuser', 'fakeuser_pass');
    }


    /**
     * Creates a mock object for admin/user Magento Model
     *
     * @return My_Module_Test_Controller_Adminhtml_Controller
     */
    protected function _registerUserMock()
    {
        $user = $this->getModelMock('admin/user');
        $user->expects($this->any())->method('getId')->will($this->returnValue(self::FAKE_USER_ID));
        $this->replaceByMock('model', 'admin/user', $user);

        return $this;
    }
} 

Unfortunately when I just start an empty test that inherits the class I got this error:

RuntimeException: Cannot run controller test, because the host is not set for base url.

app/code/community/EcomDev/PHPUnit/Controller/Request/Http.php:355
app/code/core/Mage/Core/Model/Cookie.php:105
app/code/core/Mage/Core/Model/Cookie.php:299
app/code/core/Mage/Core/Model/Session/Abstract.php:567
app/code/core/Mage/Admin/Model/Session.php:93
app/code/community/LeMike/DevMode/Test/Adminhtml.php:90
app/code/community/LeMike/DevMode/Test/Adminhtml.php:36

This class has some issues and I don't know how to fix them because the base url was given.

4