Zend framework Zend 1.11单元测试控制器测试用例

Zend framework Zend 1.11单元测试控制器测试用例,zend-framework,phpunit,Zend Framework,Phpunit,我对在我的工作流程中添加单元测试感兴趣,并且已经开始在运行PHP5.3.4和PHPUnit3.7.13的Zend Framework 1.11应用程序上创建一些测试 我编写的一个测试希望在加载应用程序时检查响应中是否出现。当仅呈现视图脚本时,测试通过,但是当我将布局路径添加到主应用程序中的application.ini时,测试失败,因为响应中未返回视图脚本(通过浏览器查看应用程序时没有错误,布局和视图呈现正确) 当终止测试并输出assertQueryContentContains()用于检查DO

我对在我的工作流程中添加单元测试感兴趣,并且已经开始在运行PHP5.3.4和PHPUnit3.7.13的Zend Framework 1.11应用程序上创建一些测试

我编写的一个测试希望在加载应用程序时检查响应中是否出现
。当仅呈现视图脚本时,测试通过,但是当我将布局路径添加到主应用程序中的application.ini时,测试失败,因为响应中未返回视图脚本(通过浏览器查看应用程序时没有错误,布局和视图呈现正确)

当终止测试并输出assertQueryContentContains()用于检查DOM元素的内容时,它显示正在加载layout.phtml,但被视为平面文件,将PHP代码显示为字符串,而不是解析

有没有一种方法可以让单元测试加载整个MVC调度循环,并像通过浏览器运行一样返回请求的内容

提前谢谢

应用程序/configs/application.ini

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
测试/bootstrap.php

/// 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'),
    'C:\wamp\bin\library',
    get_include_path(),
)));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
public function setUp()
{

    $this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
    parent::setUp();
}

public function testIndexAction()
{

    $params = array('action' => 'index', 'controller' => 'index', 'module' => 'default');
    $urlParams = $this->urlizeOptions($params);
    $url = $this->url($urlParams);
    $this->dispatch($url);

    // assertions
    $this->assertModule($urlParams['module']);
    $this->assertController($urlParams['controller']);
    $this->assertAction($urlParams['action']);


    $this->assertQueryContentContains("div#jt h1", "Unit Testing");

}
测试/应用程序/控制器/IndexControllerTest.php

/// 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'),
    'C:\wamp\bin\library',
    get_include_path(),
)));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
public function setUp()
{

    $this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
    parent::setUp();
}

public function testIndexAction()
{

    $params = array('action' => 'index', 'controller' => 'index', 'module' => 'default');
    $urlParams = $this->urlizeOptions($params);
    $url = $this->url($urlParams);
    $this->dispatch($url);

    // assertions
    $this->assertModule($urlParams['module']);
    $this->assertController($urlParams['controller']);
    $this->assertAction($urlParams['action']);


    $this->assertQueryContentContains("div#jt h1", "Unit Testing");

}
更新#1 只是为了在打印$this->getResponse()->getBody()时更清楚一点;在屏幕上,我看到:

/**
* HTML
*/
<div class="container">
    <?= $this->partial( 'partials/header.phtml' ); ?>

    <?= $this->layout()->content; ?>

    <div class="footer">
         <p>&copy; Company 2013</p>
    </div>

</div>
/**
* More HTML
*/
/**
*HTML
*/
&抄袭;公司2013

/** *更多HTML */

当我期望布局()->content;?>显示我正在测试的视图脚本中的内容。

您没有回显变量吗

<?= echo $this->partial('partials/header.phtml') ?>
<?= $this->layout()->content; ?>


另外,值得检查的是,您是否能够使用短代码PHP而不是

,谢谢您的回答。正在使用短标记回显变量