改用phpt作为默认的测试框架

以前作PHP测试的时候经常用PHPUNIT,现在个人倾向用phpt,因为非常简单,没有那些复杂的多余代码,很有python的doctest味。

--TEST--
   Description of the test case goes here
--FILE--
<?php
   Your test client written in php
?>
--EXPECT--
Expected output of the above php script


例子:
--TEST--
Sina_Helper_Log: Console Handler
--FILE--
<?php
ini_set('include_path',ini_get('include_path').":/home/hanyh/workspace/mail-trunk/webapp/SWMLibV1");

require_once("Sina/Helper/Log.php");
require_once("Sina/Helper/Log/Console.php");

$conf = array('lineFormat' => '%2$s [%3$s] %4$s');
$logger = &Sina_Helper_Log::singleton('console', '', 'ident', $conf);
for ($i = 0; $i < 3; $i++) {
	$logger->log("Log entry $i");
}

echo "\n[Buffering / Flush Test]\n";
$conf = array('lineFormat' => '%2$s [%3$s] %4$s', 'buffering' => true);
$buffered_logger = &Sina_Helper_Log::singleton('console', '', 'buffered', $conf);
for ($i = 0; $i < 3; $i++) {
    $buffered_logger->log("Pre-flush buffered log entry $i");
}
echo "Pre-flush\n";
$buffered_logger->flush();
echo "Post-flush\n";
for ($i = 0; $i < 3; $i++) {
    $buffered_logger->log("Post-flush buffered log entry $i");
}
echo "Shutdown\n";
$buffered_logger->close();

--EXPECT--
ident [info] Log entry 0
ident [info] Log entry 1
ident [info] Log entry 2

[Buffering / Flush Test]
Pre-flush
buffered [info] Pre-flush buffered log entry 0
buffered [info] Pre-flush buffered log entry 1
buffered [info] Pre-flush buffered log entry 2
Post-flush
Shutdown
buffered [info] Post-flush buffered log entry 0
buffered [info] Post-flush buffered log entry 1
buffered [info] Post-flush buffered log entry 2




你可能感兴趣的:(PHP,框架,python)