public function testReader() { $handle = fopen(dirname(__FILE__) . '/stdin', 'w+'); $outputter = new Outputter($this); $reader = new Reader($handle, $outputter); fputs($handle, "yes\n"); $out = $reader->readLine("Input prompt:"); //$this->assertSame("yes", $out); ob_start(); var_dump($handle); $dump = trim(ob_get_clean()); $this->assertTrue(strpos($dump, 'of type (stream)') > 0); unset($reader); // free up handler ob_start(); var_dump($handle); $dump = trim(ob_get_clean()); $this->assertTrue(strpos($dump, 'of type (Unknown)') > 0); unlink(dirname(__FILE__) . '/stdin'); }
/** * Read-line either from STDIN or mock unit test data * * @return string */ public function readLine() { if (null !== $this->unitTestData) { return $this->unitTestData; } else { $outputter = new PlainOutputter(); $reader = new Reader(); return $reader->setOutputter($outputter)->readLine("Type 'yes' to continue: "); } }