2017-01-27 20 views

回答

2

best way(2017年),以檢查測試代碼的輸出是使用功能expectOutputString()

class DebugTest extends PHPUnit_Framework_TestCase 
{ 
    public function test() 
    { 
     // Set the expectation 
     $this->expectOutputString('foo'); 

     // Run the tested code 
     $d = new Debug; 
     $d->log('foo'); 
    } 
} 

幕後,expectOutputString()爲你做緩衝伎倆。
該方法自PHPUnit 3.6.0(即超過5年前發佈)開始提供。

相關問題