【发布时间】:2011-10-29 04:54:25
【问题描述】:
我已经设法通过我的 Zend Framework 项目设置 PHPUnit,使用 Phing 在构建时通过 Eclipse 外部工具执行测试。我的测试是在构建时找到并执行的,但由于某种原因,页面中的 PHP 没有被解释。
为了弄清楚我的断言失败的原因,我在我的测试中添加了:echo $this->response->outputBody();,并意识到它与原始 PHP 相呼应。如果我添加 echo get_class($this->response); 我会得到 Zend_Controller_Response_HttpTestCase 作为类名,从我收集的信息来看是正确的。
我在 Apache 上遇到过这个问题,其中文件处理程序未设置为通过 PHP 可执行文件发送 PHP 代码,但据我所知,这应该不是问题,因为 Phing/PHPUnit 应该处理执行所有内容直接通过可执行文件。我对 PHPUnit 或 Phing 的工作原理还不够了解,无法知道我可能做错了什么。有什么建议吗?
这是我的测试类:
<?php
class SearchControllerTest extends ControllerTestCase
{
public function setUp()
{
parent::setUp();
}
public function testSearchPizzaChicago()
{
$this->_search('restaurants', 'chicago, il');
}
private function _search($what, $where)
{
$this->request->setMethod('POST');
$this->request->setPost(
array(
'search_what' => $what,
'search_where' => $where,
)
);
$this->dispatch(Zend_Registry::get('base_url') . '/search/results');
echo $this->response->outputBody();
//echo get_class($this->response);
$this->assertQuery('#results');
}
public function tearDown()
{
/* Tear Down Routine */
}
}
这是我运行其中一项测试时的控制台输出:
Buildfile: C:\workspace\myproject\build.xml
myproject > test:
... raw PHP code here ...
[phpunit] Testsuite: SearchControllerTest
[phpunit] Tests run: 1, Failures: 1, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.25874 s
[phpunit] testSearchPizzaChicago FAILED
[phpunit] Failed asserting node DENOTED BY #results EXISTS
[phpunit] C:\workspace\frameworks\ZendFramework-1.11\library\Zend\Test\PHPUnit\Constraint\DomQuery.php:263
[phpunit] C:\workspace\frameworks\ZendFramework-1.11\library\Zend\Test\PHPUnit\ControllerTestCase.php:300
[phpunit] C:\workspace\myproject\tests\application\controllers\SearchControllerTest.php:34
[phpunit] C:\workspace\myproject\tests\application\controllers\SearchControllerTest.php:13
[phpunit] C:\wamp\bin\php\php5.3.5\PEAR\phing.php:37
BUILD FINISHED
Total time: 2.0895 seconds
【问题讨论】:
-
您是否在输出的原始代码中使用短标签( ?> 或 = ?>)?如果您的服务器未设置 php 短标签,则不会将它们作为 PHP 处理,您将遇到类似于此的问题
标签: php eclipse zend-framework phpunit phing