I have reader class which read from stdin and return readed value.
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);
}
}
Now is my question, how I can test this class, reading something from stdin and return readed value by getReadedValue()
function?
You test the Reader, not if STDIN is working or not.
Because you test the unit (the Reader) it is not important what that filename is as it is only optional. You can inject something different, for example the filename of a temporary file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With