Skip to content

Instantly share code, notes, and snippets.

@co3k
Created May 16, 2011 12:43
Show Gist options
  • Save co3k/974382 to your computer and use it in GitHub Desktop.
Save co3k/974382 to your computer and use it in GitHub Desktop.
対話型タスクのテストをする奴の書き殴り中実戦投入中の奴
<?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);
}
}
@co3k
Copy link
Author

co3k commented May 16, 2011

recording はやり過ぎた

@co3k
Copy link
Author

co3k commented May 16, 2011

やるならやるでポリモりたい

@co3k
Copy link
Author

co3k commented May 17, 2011

レコード機能終了のお知らせ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment