|
small and function php unit test framework . required php 5.1. <?php
/** * 图书 模型
* * @author KenXu * @date: 2010-7-28 下午05:57:47
*/
class Book {
/** * @var Kenxu_Mysql */
private $_db = null;
function __construct(){
// 初始化 对象
$this->_db = new Kenxu_Mysql();
$this->_db->connect('localhost','root','root','test','utf8');
}
function fetchBooks(){
$books = $this->_db->fetch_all('select * from books') ;
return $books ;
}
};
<?php
class BookTest extends Kenxu_Unit_TestCase {
/** * @var Book $_modBook
*/
private $_modBook = null ;
function setUp(){
/* Setup Routine */
$this->_modBook = new Book() ;
}
function fetchBooksTest(){
$books = $this->_modBook->fetchBooks() ;
Kenxu_Unit_Assert::assertThat( count($books),array(array('equal',3, '图书个数为3')) ,'测试图书元素' );
Kenxu_Unit_Assert::assertThat( !$books,array(array('not_empty','值不能为空')) ,'测试图书元素' );
Kenxu_Unit_Assert::assertNotNull( !$books,'图书表中数据为空' );
}
function tearDown(){
/* Tear Down Routine */
$this->_modBook = null ;
}
}
intro: http://vb2005xu.javaeye.com/blog/760561
|