8
我有從stdin讀取並返回相關值的讀取器類。如何在PHPUnit中測試STDIN
class Reader
{
const STREAM_READ = 'php://stdin';
private $_streamHandle;
public function __construct($stream = self::STREAM_READ)
{
$this->_streamHandle = fopen($stream, 'r');
}
public function getReadedValue()
{
$value = trim(fgets($this->_streamHandle));
return $value;
}
public function __destruct()
{
fclose($this->_streamHandle);
}
}
現在是我的問題,我怎麼能測試這個類,從標準輸入讀的東西和getReadedValue()
函數返回值readed?
使用命令行執行腳本 – 2013-04-11 19:47:53
PHPUnit有一個名爲vfsStream的文件系統模擬擴展,我認爲這可能會有所幫助,但文檔不會說什麼,所以也許不會。也許值得一挖雖然?它在GitHub上。或者,下面是一個相關的QA,可能值得一讀:http://stackoverflow.com/questions/9158155/how-to-write-unit-tests-for-interactive-console-app – 2013-04-11 19:55:39