Drupal investigation

CommandTest.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Finder\Tests\Shell;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Finder\Shell\Command;
  13. /**
  14. * @group legacy
  15. */
  16. class CommandTest extends TestCase
  17. {
  18. public function testCreate()
  19. {
  20. $this->assertInstanceOf('Symfony\Component\Finder\Shell\Command', Command::create());
  21. }
  22. public function testAdd()
  23. {
  24. $cmd = Command::create()->add('--force');
  25. $this->assertSame('--force', $cmd->join());
  26. }
  27. public function testAddAsFirst()
  28. {
  29. $cmd = Command::create()->add('--force');
  30. $cmd->addAtIndex(Command::create()->add('-F'), 0);
  31. $this->assertSame('-F --force', $cmd->join());
  32. }
  33. public function testAddAsLast()
  34. {
  35. $cmd = Command::create()->add('--force');
  36. $cmd->addAtIndex(Command::create()->add('-F'), 1);
  37. $this->assertSame('--force -F', $cmd->join());
  38. }
  39. public function testAddInBetween()
  40. {
  41. $cmd = Command::create()->add('--force');
  42. $cmd->addAtIndex(Command::create()->add('-F'), 0);
  43. $cmd->addAtIndex(Command::create()->add('-X'), 1);
  44. $this->assertSame('-F -X --force', $cmd->join());
  45. }
  46. public function testCount()
  47. {
  48. $cmd = Command::create();
  49. $this->assertSame(0, $cmd->length());
  50. $cmd->add('--force');
  51. $this->assertSame(1, $cmd->length());
  52. $cmd->add('--run');
  53. $this->assertSame(2, $cmd->length());
  54. }
  55. public function testTop()
  56. {
  57. $cmd = Command::create()->add('--force');
  58. $cmd->top('--run');
  59. $this->assertSame('--run --force', $cmd->join());
  60. }
  61. public function testTopLabeled()
  62. {
  63. $cmd = Command::create()->add('--force');
  64. $cmd->top('--run');
  65. $cmd->ins('--something');
  66. $cmd->top('--something');
  67. $this->assertSame('--something --run --force ', $cmd->join());
  68. }
  69. public function testArg()
  70. {
  71. $cmd = Command::create()->add('--force');
  72. $cmd->arg('--run');
  73. $this->assertSame('--force '.escapeshellarg('--run'), $cmd->join());
  74. }
  75. public function testCmd()
  76. {
  77. $cmd = Command::create()->add('--force');
  78. $cmd->cmd('run');
  79. $this->assertSame('--force run', $cmd->join());
  80. }
  81. public function testInsDuplicateLabelException()
  82. {
  83. $cmd = Command::create()->add('--force');
  84. $cmd->ins('label');
  85. $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
  86. $cmd->ins('label');
  87. }
  88. public function testEnd()
  89. {
  90. $parent = Command::create();
  91. $cmd = Command::create($parent);
  92. $this->assertSame($parent, $cmd->end());
  93. }
  94. public function testEndNoParentException()
  95. {
  96. $cmd = Command::create();
  97. $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
  98. $cmd->end();
  99. }
  100. public function testGetMissingLabelException()
  101. {
  102. $cmd = Command::create();
  103. $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
  104. $cmd->get('invalid');
  105. }
  106. public function testErrorHandler()
  107. {
  108. $cmd = Command::create();
  109. $handler = function () { return 'error-handler'; };
  110. $cmd->setErrorHandler($handler);
  111. $this->assertSame($handler, $cmd->getErrorHandler());
  112. }
  113. public function testExecute()
  114. {
  115. $cmd = Command::create();
  116. $cmd->add('php');
  117. $cmd->add('--version');
  118. $result = $cmd->execute();
  119. $this->assertInternalType('array', $result);
  120. $this->assertNotEmpty($result);
  121. $this->assertRegExp('/PHP|HipHop/', $result[0]);
  122. }
  123. public function testCastToString()
  124. {
  125. $cmd = Command::create();
  126. $cmd->add('--force');
  127. $cmd->add('--run');
  128. $this->assertSame('--force --run', (string) $cmd);
  129. }
  130. }