dev-master
9999999-devIterator to read STDIN line by line
MIT
The Development Requires
by Yuki Fujii
1.1.0
1.1.0.0Iterator to read STDIN line by line
MIT
The Development Requires
by Yuki Fujii
Wallogit.com
2017 © Pedro Peláez
Iterator to read STDIN line by line
use Hikaeme\StdinIterator;
$stdin = new StdinIterator();
foreach ($stdin as $line) {
echo $line;
}
composer require hikaeme/stdin-iterator
class SampleCommand
{
private $stdin;
public function __construct(StdinIterator $stdin = null)
{
$this->stdin = $stdin ?: new StdinIterator();
}
public function run()
{
foreach ($this->stdin as $line) {
echo $line;
}
}
}
class SampleCommandTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
$stub = new StdinIteratorStub();
$stub->setStdin("1\n2\n3\n");
$command = new \SampleCommand($stub);
ob_start();
$command->run();
$result = ob_get_clean();
$this->assertSame("1\n2\n3\n", $result);
}
}
Iterator to read STDIN line by line
MIT
Iterator to read STDIN line by line
MIT