2010-12-13 12 views

回答

2

Install PHPUnit.Run the following UnitTest:

// make sure PHPUnit is included 

class DateTest extends PHPUnit_Framework_TestCase 
{ 
    public function setup() 
    { 
     date_default_timezone_set('UTC'); 
    } 
    public function getDates() 
    { 
     return array(
      array('01', 'Jan'), 
      array('02', 'Feb'), 
      array('03', 'Mar'), 
      array('04', 'Apr'), 
      array('05', 'May'), 
      array('06', 'Jun'), 
      array('07', 'Jul'), 
      array('08', 'Aug'), 
      array('09', 'Sep') 
     ); 
    } 
    /** 
    * @dataProvider getDates 
    */ 
    public function testDateReturnsMonthWithLeadingZero($expected, $month) 
    { 
     $this->assertSame($expected, date('m', strtotime($month))); 
    } 
} 

如果測試失敗並出現任何給定的測試日期,請收集您的PHP版本和操作系統,並向PHP錯誤跟蹤器報告錯誤。如果測試通過了所有測試日期,那麼您正在做其他事情。

相關問題