public static function get_all() { $db = Authors::get_db(); $res = $db->query( "SELECT * FROM authors" ); $rows = array(); while( $res->fetchInto( $row ) ) { $rows []= $row; } return $rows; } } ?> 在对这段代码运行测试时,所有的测试都可以没有问题地运行,这样我们就可以知道自己的代码可以正确工作了。 HTML 测试 对整个 PHP 应用程序进行测试的下一个步骤是对前端的超文本标记语言(HTML)界面进行测试。要进行这种测试,我们需要一个如下所示的 Web 页面。 这个页面对两个数字进行求和。为了对这个页面进行测试,我们首先从单元测试代码开始入手。 清单 10. TestPage.php <?php require_once 'HTTP/Client.php'; require_once 'PHPUnit2/Framework/TestCase.php'; class TestPage extends PHPUnit2_Framework_TestCase { function get_page( $url ) { $client = new HTTP_Client(); $client->get( $url ); $resp = $client->currentResponse(); return $resp['body']; } function test_get() { $page = TestPage::get_page( 'http://localhost/unit/add.php' ); $this->assertTrue( strlen( $page ) > 0 ); $this->assertTrue( preg_match( '/<html>/', $page ) == 1 ); } function test_add() { $page = TestPage::get_page( 'http://localhost/unit/add.php?a=10&b=20' ); $this->assertTrue( strlen( $page ) > 0 ); $this->assertTrue( preg_match( '/<html>/', $page ) == 1 ); preg_match( '/<span id="result">(.*?)<\/span>/', $page, $out ); $this->assertTrue( $out[1]=='30' ); } } ?>
关于网站 | 客服中心 | 服务条款 | 友情链接 | 广告联系 | 本站历程 | 网站导航
吉ICP备05000107号