/tests/Aura/Framework/Cli/AbstractCommandTest.php
PHP | 91 lines | 66 code | 20 blank | 5 comment | 1 complexity | 27da5ad79260835508734ee1797ffe96 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- namespace Aura\Framework\Cli;
- use Aura\Cli\Getopt as Getopt;
- use Aura\Cli\Stdio as Stdio;
- use Aura\Cli\Vt100 as Vt100;
- use Aura\Cli\Context as Context;
- use Aura\Cli\OptionFactory as OptionFactory;
- use Aura\Signal\Manager;
- use Aura\Signal\HandlerFactory;
- use Aura\Signal\ResultFactory;
- use Aura\Signal\ResultCollection;
- use Aura\Framework\Mock\System;
- /**
- * Test class for Command.
- * Generated by PHPUnit on 2011-05-27 at 11:01:31.
- */
- abstract class AbstractCommandTest extends \PHPUnit_Framework_TestCase
- {
- protected $command_name;
-
- protected $stdio;
-
- protected $getopt;
-
- protected $system;
-
- protected $tmp_dir;
-
- protected $context;
-
- protected $signal;
-
- protected $outfile;
-
- protected $errfile;
-
- public function setUp()
- {
- $root = dirname(dirname(dirname(__DIR__)));
- $this->system = System::newInstance($root);
- $this->system->create();
- }
-
- public function tearDown()
- {
- parent::tearDown();
- if ($this->stdio) {
- fclose($this->stdio->getStdout());
- fclose($this->stdio->getStderr());
- }
- unlink($this->outfile);
- unlink($this->errfile);
- $this->system->remove();
- }
-
- protected function newCommand($argv = [])
- {
- $_SERVER['argv'] = $argv;
-
- $this->context = new Context($GLOBALS);
-
- $sub = "test/Aura.Framework/Cli/{$this->command_name}/Command";
- $this->tmp_dir = $this->system->getTmpPath();
-
- // use files because we can't use php://memory in proc_open() calls
- $this->outfile = tempnam($this->tmp_dir, '');
- $this->errfile = tempnam($this->tmp_dir, '');
-
- $stdin = fopen('php://stdin', 'r');
- $stdout = fopen($this->outfile, 'w+');
- $stderr = fopen($this->errfile, 'w+');
- $vt100 = new Vt100;
-
- $this->stdio = new Stdio($stdin, $stdout, $stderr, $vt100);
-
- $option_factory = new OptionFactory();
- $this->getopt = new Getopt($option_factory);
-
- $this->signal = new Manager(new HandlerFactory, new ResultFactory, new ResultCollection);
-
- $class = "\Aura\Framework\Cli\\{$this->command_name}\Command";
- $command = new $class(
- $this->context,
- $this->stdio,
- $this->getopt
- );
- $command->setSignal($this->signal);
- return $command;
- }
- }