我正在嘗試使用PHPunit來測試輸出一些自定義頭文件的類。PHPUnit測試PHP頭文件
的問題是,我的機器上這一點:
<?php
class HeadersTest extends PHPUnit_Framework_TestCase {
public function testHeaders()
{
ob_start();
header('Location: foo');
$headers_list = headers_list();
header_remove();
ob_clean();
$this->assertContains('Location: foo', $headers_list);
}
}
,甚至這樣的:
<?php
class HeadersTest extends PHPUnit_Framework_TestCase {
public function testHeaders()
{
ob_start();
header('Location: foo');
header_remove();
ob_clean();
}
}
這個錯誤:
[email protected] [~/test]# phpunit --verbose HeadersTest.php
PHPUnit 3.6.10 by Sebastian Bergmann.
E
Time: 0 seconds, Memory: 2.25Mb
There was 1 error:
1) HeadersTest::testHeaders
Cannot modify header information - headers already sent by (output started at /usr/local/lib/php/PHPUnit/Util/Printer.php:173)
/test/HeadersTest.php:9
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
這看起來好像有別的東西在測試運行之前輸出到終端,即使沒有包含其他文件並且沒有其他字符在PHP標籤開始之前。它可能是PHPunit內導致這種情況的東西嗎?
問題是什麼?
只是想,如果有興趣在此另一些人,以及覆蓋這一點。在運行PHPunit(使用PHP CLI)時,headers_list()不起作用,但xdebug_get_headers()可以起作用。 – titel 2012-03-18 17:26:23