PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Aura/Cli/CommandTest.php

https://bitbucket.org/harikt/aura.cli
PHP | 46 lines | 33 code | 6 blank | 7 comment | 0 complexity | 080b36e6fc98fb113c561504bc48e02e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Aura\Cli;
  3. /**
  4. * Test class for Command.
  5. */
  6. class CommandTest extends \PHPUnit_Framework_TestCase
  7. {
  8. protected function newMockCommand($argv = [], $class = 'Aura\Cli\MockCommand')
  9. {
  10. // standard input/output
  11. $stdin = fopen('php://memory', 'r');
  12. $stdout = fopen('php://memory', 'w+');
  13. $stderr = fopen('php://memory', 'w+');
  14. $vt100 = new Vt100;
  15. $stdio = new Stdio($stdin, $stdout, $stderr, $vt100);
  16. // getopt
  17. $option_factory = new OptionFactory();
  18. $getopt = new Getopt($option_factory);
  19. // Command
  20. $_SERVER['argv'] = $argv;
  21. $context = new Context($GLOBALS);
  22. return new $class($context, $stdio, $getopt);
  23. }
  24. public function testExec()
  25. {
  26. $expect = ['foo', 'bar', 'baz', 'dib'];
  27. $command = $this->newMockCommand($expect);
  28. $command->exec();
  29. // did the params get passed in?
  30. $actual = $command->params;
  31. $this->assertSame($expect, $actual);
  32. }
  33. public function testExec_hooks()
  34. {
  35. $command = $this->newMockCommand();
  36. $command->exec();
  37. $this->assertTrue($command->_pre_action);
  38. $this->assertTrue($command->_post_action);
  39. }
  40. }