views:

20

answers:

0

Hello. I try to write test for controller. I use OS Windows, zend framewokr and my libraries are in C:/library which is added to the include_path of php.ini. When I run test testLoginAction I get an error No default moudulde define for the application. But I don't use modules at all. Do you know how to solve this problem? IndexControllerTest.php

class Controller_IndexControllerTest extends ControllerTestCase { public function testIsEverythingOK() { $this->assertTrue(true); }

public function testLoginAction()
{
        $this->dispatch('/login/index');
        $this->assertModule('default');
        $this->assertController('login');
        $this->assertAction('index');
}

}

ControllerTestCase.php

require_once 'Zend/Application.php'; require_once 'Zend/Controller/Action.php'; require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';

class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase { protected $_application;

public function setUp()
{
    $this->bootstap = array($this, 'appBootstrap');     
    parent::setUp();
}

public function appBootstrap()
{

// require dirname(FILE) . '/bootstrap.php';

    $this->front->setControllerDirectory('../application/controllers');     
    $this->_application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini');
    $this->_application->bootstrap();
}   

}

My phpunit.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="./application/bootstrap.php"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    stopOnFailure="true"
    syntaxCheck="true">

    <!-- запускаем все тесты из корневой директории -->
    <testsuite name="Main Test Suite">
        <directory>./</directory>
    </testsuite>

        <filter>            <!-- смотрим лишь на следующие директории -->
        <whitelist>
                  <directory suffix=".php">../application</directory>

../library--> ../application ../application/forms ../application/models
../library
../application/Bootstrap.php

My bootstrap.php in tests/application:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'ControllerTestCase.php';

My Base class for tests:

require_once 'Zend/Application.php'; require_once 'Zend/Controller/Action.php'; require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';

class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase { protected $_application;

public function setUp()
{
    $this->bootstap = array($this, 'appBootstrap');     
    parent::setUp();
}

public function appBootstrap()
{

// require dirname(FILE) . '/bootstrap.php';

    $this->front->setControllerDirectory('../application/controllers');     
    $this->_application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini');
    $this->_application->bootstrap();
}   

}

Best regards, Oleg.