Created
May 16, 2011 12:43
-
-
Save co3k/974382 to your computer and use it in GitHub Desktop.
対話型タスクのテストをする奴の書き殴り中実戦投入中の奴
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class opInteractiveTaskTestHandler | |
{ | |
public $cli, $t, $lastStatus, $resource = null; | |
public $pipes = array(); | |
public $output = ''; | |
public function __construct($t) | |
{ | |
$this->t = $t; | |
$this->cli = sfToolkit::getPhpCli(); | |
} | |
public function execute($cmd, $inputs = array()) | |
{ | |
$symfony = dirname(__FILE__).'/../../../symfony'; | |
$descriptorspec = array( | |
0 => array('pipe', 'r'), // stdin | |
1 => array('pipe', 'w'), // stdout | |
); | |
$commandString = $this->cli.' '.$symfony.' '.$cmd; | |
$this->resource = proc_open($commandString, $descriptorspec, $this->pipes); | |
$this->t->info('Exceuted the specified "'.$commandString.'"'); | |
return $this; | |
} | |
public function output($display = false) | |
{ | |
$this->output = fgets($this->pipes[1]); | |
if ($display) { | |
$this->t->info('Output: '.trim($this->output)); | |
} | |
return $this; | |
} | |
public function outputUntil($expected) | |
{ | |
while ($this->output()) { | |
if (trim($this->output) === $expected) { | |
$this->t->info('Matched with expected output "'.$expected.'"'); | |
return $this; | |
} | |
} | |
} | |
public function input($input) | |
{ | |
$this->t->info('Input '.$input); | |
fwrite($this->pipes[0], $input.PHP_EOL); | |
return $this; | |
} | |
public function testOutput($expected, $comment = '') | |
{ | |
$this->t->is(trim($this->output), $expected, $comment); | |
return $this; | |
} | |
public function printOutput() | |
{ | |
$this->t->info('Output : '.trim($this->output)); | |
return $this; | |
} | |
public function shutdown() | |
{ | |
foreach ($this->pipes as $pipe) { | |
fclose($pipe); | |
} | |
proc_close($this->resource); | |
} | |
} |
やるならやるでポリモりたい
レコード機能終了のお知らせ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
recording はやり過ぎた