PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Aura/Framework/Cli/AbstractCommandTest.php

https://bitbucket.org/harikt/aura.framework
PHP | 91 lines | 66 code | 20 blank | 5 comment | 1 complexity | 27da5ad79260835508734ee1797ffe96 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Aura\Framework\Cli;
  3. use Aura\Cli\Getopt as Getopt;
  4. use Aura\Cli\Stdio as Stdio;
  5. use Aura\Cli\Vt100 as Vt100;
  6. use Aura\Cli\Context as Context;
  7. use Aura\Cli\OptionFactory as OptionFactory;
  8. use Aura\Signal\Manager;
  9. use Aura\Signal\HandlerFactory;
  10. use Aura\Signal\ResultFactory;
  11. use Aura\Signal\ResultCollection;
  12. use Aura\Framework\Mock\System;
  13. /**
  14. * Test class for Command.
  15. * Generated by PHPUnit on 2011-05-27 at 11:01:31.
  16. */
  17. abstract class AbstractCommandTest extends \PHPUnit_Framework_TestCase
  18. {
  19. protected $command_name;
  20. protected $stdio;
  21. protected $getopt;
  22. protected $system;
  23. protected $tmp_dir;
  24. protected $context;
  25. protected $signal;
  26. protected $outfile;
  27. protected $errfile;
  28. public function setUp()
  29. {
  30. $root = dirname(dirname(dirname(__DIR__)));
  31. $this->system = System::newInstance($root);
  32. $this->system->create();
  33. }
  34. public function tearDown()
  35. {
  36. parent::tearDown();
  37. if ($this->stdio) {
  38. fclose($this->stdio->getStdout());
  39. fclose($this->stdio->getStderr());
  40. }
  41. unlink($this->outfile);
  42. unlink($this->errfile);
  43. $this->system->remove();
  44. }
  45. protected function newCommand($argv = [])
  46. {
  47. $_SERVER['argv'] = $argv;
  48. $this->context = new Context($GLOBALS);
  49. $sub = "test/Aura.Framework/Cli/{$this->command_name}/Command";
  50. $this->tmp_dir = $this->system->getTmpPath();
  51. // use files because we can't use php://memory in proc_open() calls
  52. $this->outfile = tempnam($this->tmp_dir, '');
  53. $this->errfile = tempnam($this->tmp_dir, '');
  54. $stdin = fopen('php://stdin', 'r');
  55. $stdout = fopen($this->outfile, 'w+');
  56. $stderr = fopen($this->errfile, 'w+');
  57. $vt100 = new Vt100;
  58. $this->stdio = new Stdio($stdin, $stdout, $stderr, $vt100);
  59. $option_factory = new OptionFactory();
  60. $this->getopt = new Getopt($option_factory);
  61. $this->signal = new Manager(new HandlerFactory, new ResultFactory, new ResultCollection);
  62. $class = "\Aura\Framework\Cli\\{$this->command_name}\Command";
  63. $command = new $class(
  64. $this->context,
  65. $this->stdio,
  66. $this->getopt
  67. );
  68. $command->setSignal($this->signal);
  69. return $command;
  70. }
  71. }