How to check STDIN in PHPUnit

I have a reader class that reads from stdin and return 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 my question is, how can I test this class by reading something from stdin and return value using getReadedValue() function?

+8
php tdd testing phpunit bdd
source share
1 answer

You are testing Reader, not if STDIN is working or not.

Since you are checking the device (Reader), it does not matter what the file name is, since it is optional. You can enter something else, such as the file name of a temporary file.

+1
source share

All Articles