PHPUnitで実行されているPHPTテストがいくつかあります。これらのテストには、--CLEAN--
テスト中に作成されたファイルの削除を処理するセクションが含まれています。を使用してコマンドラインでPHPTテストを実行すると正常に機能しますpear run-tests
が、PHPUnitを使用して実行すると、次のエラーが発生します。
BORKED --CLEAN--セクション!出力:
X-Powered-By:PHP / 5.3.10-1ubuntu3.2
コンテンツタイプ:text / html
これは明らかにHTTPヘッダーのように見えますが、それ以上のテキストはなく、クリーンセクションのアクションは引き続き計画どおりに機能します。CLEANセクションを削除すると問題は解決しますが、PHPTファイルの外部でテストのクリーンアップを実行したくありません。これらが何によって引き起こされているのか、そしてそれらを取り除く方法についてのアイデアはありますか?それらはテストを破っていませんが、出力では乱雑に見えます。
PHPTテスト(私の雇用を保護するためにPOSTファイルデータは切り捨てられます):
--TEST--
Test file upload
--POST_RAW--
Content-Type: multipart/form-data; boundary=---------------------------168481652011378167832091260413
Content-Length: 3510
-----------------------------168481652011378167832091260413
Content-Disposition: form-data; name="code"
te
-----------------------------168481652011378167832091260413
Content-Disposition: form-data; name="name"
test
-----------------------------168481652011378167832091260413
Content-Disposition: form-data; name="file"; filename="test.xml"
Content-Type: text/xml
<?xml version="1.0" encoding="utf-8"?>
<testElement>
<innerElement />
</testElement>
-----------------------------168481652011378167832091260413--
--FILE--
<?php
// Zend/PHPUnit bootstrap
require_once __DIR__ . '/../../../bootstrap.php';
$upload = new My_File_Upload();
var_dump($upload->handleFile(
'file',
APPLICATION_PATH . '/../datafiles/request/',
'application/xml',
'testname'
));
var_dump(file_exists(APPLICATION_PATH . '/../datafiles/request/testname.xml'))
?>
--CLEAN--
<?php
$file = dirname(__FILE__) . '/../../../../datafiles/request/testname.xml';
if(file_exists($file)) unlink($file);
?>
--EXPECT--
string(12) "testname.xml"
bool(true)
Zend / PHPUnitテストラッパー:
<?php
require_once 'PHPUnit/Extensions/PhptTestCase.php';
/**
* UploadFileHandleTest
*
* PHPUnit wrapper for the phpt test file UploadFileHandleTest.phpt
*
*/
class My_File_UploadFileHandle extends PHPUnit_Extensions_PhptTestCase
{
/**
* Test file uploads
*
* Test the file uploads using associated .phpt test files. These test have to
* be abstracted to the php-cgi environment to permit accurate manipulation of
* the $_FILES superglobal.
*
* @see http://qafoo.com/blog/013_testing_file_uploads_with_php.html
*
* @covers My_File_Upload::handleFile
*
* @return void
*/
public function __construct()
{
parent::__construct(__DIR__ . '/UploadFileHandleTest.phpt');
}
/**
* Implement missing hasOutput method for PHPUnit
*
* @return boolean
*/
public function hasOutput()
{
return false;
}
}
ラッパーをトリガーするテストスイート:
<?php
require_once 'UploadFileExists.php';
require_once 'UploadFileHandle.php';
require_once 'UploadFileHandleNoName.php';
require_once 'UploadFileHandleExceptions.php';
class My_File_UploadTestSuite extends PHPUnit_Framework_TestSuite
{
public static function suite()
{
$suite = new My_File_UploadTestSuite('My_File_UploadFileTests');
$suite->addTest(new My_File_UploadFileExists());
$suite->addTest(new My_File_UploadFileHandle());
$suite->addTest(new My_File_UploadFileHandleNoName());
$suite->addTest(new My_File_UploadFileHandleExceptions());
return $suite;
}
}