ConsoleIntegrationTestCaseTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Cake\Test\TestCase\TestSuite;
  3. use Cake\Console\Shell;
  4. use Cake\Core\Configure;
  5. use Cake\TestSuite\ConsoleIntegrationTestCase;
  6. class ConsoleIntegrationTestCaseTest extends ConsoleIntegrationTestCase
  7. {
  8. /**
  9. * setUp
  10. *
  11. * @return void
  12. */
  13. public function setUp()
  14. {
  15. parent::setUp();
  16. Configure::write('App.namespace', 'TestApp');
  17. }
  18. /**
  19. * tests exec when using the command runner
  20. *
  21. * @return void
  22. */
  23. public function testExecWithCommandRunner()
  24. {
  25. $this->enableCommandRunner();
  26. $this->exec('routes');
  27. $this->assertOutputContains('Welcome to CakePHP');
  28. $this->assertExitCode(Shell::CODE_SUCCESS);
  29. }
  30. /**
  31. * tests exec
  32. *
  33. * @return void
  34. */
  35. public function testExec()
  36. {
  37. $this->exec('');
  38. $this->assertOutputContains('Welcome to CakePHP');
  39. $this->assertExitCode(Shell::CODE_ERROR);
  40. }
  41. /**
  42. * tests a valid core command
  43. *
  44. * @return void
  45. */
  46. public function testExecCoreCommand()
  47. {
  48. $this->exec('routes');
  49. $this->assertOutputContains('Welcome to CakePHP');
  50. $this->assertExitCode(Shell::CODE_SUCCESS);
  51. }
  52. /**
  53. * tests exec with an arg and an option
  54. *
  55. * @return void
  56. */
  57. public function testExecWithArgsAndOption()
  58. {
  59. $this->exec('integration args_and_options arg --opt="some string"');
  60. $this->assertOutputContains('arg: arg');
  61. $this->assertOutputContains('opt: some string');
  62. $this->assertExitCode(Shell::CODE_SUCCESS);
  63. }
  64. /**
  65. * tests exec with missing required argument
  66. *
  67. * @return void
  68. */
  69. public function testExecWithMissingRequiredArg()
  70. {
  71. $this->exec('integration args_and_options');
  72. $this->assertErrorContains('Missing required arguments');
  73. $this->assertErrorContains('arg is required');
  74. $this->assertExitCode(Shell::CODE_ERROR);
  75. }
  76. /**
  77. * tests exec with input
  78. *
  79. * @return void
  80. */
  81. public function testExecWithInput()
  82. {
  83. $this->exec('integration bridge', ['javascript']);
  84. $this->assertErrorContains('No!');
  85. $this->assertExitCode(Shell::CODE_ERROR);
  86. }
  87. /**
  88. * tests exec with multiple inputs
  89. *
  90. * @return void
  91. */
  92. public function testExecWithMultipleInput()
  93. {
  94. $this->exec('integration bridge', ['cake', 'blue']);
  95. $this->assertOutputContains('You may pass');
  96. $this->assertExitCode(Shell::CODE_SUCCESS);
  97. }
  98. /**
  99. * tests _commandStringToArgs
  100. *
  101. * @return void
  102. */
  103. public function testCommandStringToArgs()
  104. {
  105. $result = $this->_commandStringToArgs('command --something=nothing --with-spaces="quote me on that"');
  106. $expected = [
  107. 'command',
  108. '--something=nothing',
  109. '--with-spaces=quote me on that'
  110. ];
  111. $this->assertSame($expected, $result);
  112. }
  113. }