CommandRunnerTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.5.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\Console;
  16. use Cake\Console\CommandCollection;
  17. use Cake\Console\CommandRunner;
  18. use Cake\Core\Configure;
  19. use Cake\Http\BaseApplication;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * Test case for the CommandCollection
  23. */
  24. class CommandRunnerTest extends TestCase
  25. {
  26. public function setUp()
  27. {
  28. parent::setUp();
  29. Configure::write('App.namespace', 'TestApp');
  30. $this->config = dirname(dirname(__DIR__));
  31. }
  32. /**
  33. * Test that the console hook not returning a command collection
  34. * raises an error.
  35. *
  36. * @expectedException \RuntimeException
  37. * @expectedExceptionMessage The application's `console` method did not return a CommandCollection.
  38. * @return void
  39. */
  40. public function testRunConsoleHookFailure()
  41. {
  42. $app = $this->getMockBuilder(BaseApplication::class)
  43. ->setMethods(['console', 'middleware', 'bootstrap'])
  44. ->setConstructorArgs([$this->config])
  45. ->getMock();
  46. $runner = new CommandRunner($app);
  47. $runner->run(['cake', '-h']);
  48. }
  49. /**
  50. * Test that running with empty argv fails
  51. *
  52. * @expectedException \RuntimeException
  53. * @expectedExceptionMessage Unknown root command. Was expecting `cake`
  54. * @return void
  55. */
  56. public function testRunMissingRootCommand()
  57. {
  58. $app = $this->getMockBuilder(BaseApplication::class)
  59. ->setMethods(['middleware', 'bootstrap'])
  60. ->setConstructorArgs([$this->config])
  61. ->getMock();
  62. $runner = new CommandRunner($app);
  63. $runner->run([]);
  64. }
  65. /**
  66. * Test that running an unknown command raises an error.
  67. *
  68. * @expectedException \RuntimeException
  69. * @expectedExceptionMessage Unknown root command `bad`. Was expecting `cake`
  70. * @return void
  71. */
  72. public function testRunInvalidRootCommand()
  73. {
  74. $app = $this->getMockBuilder(BaseApplication::class)
  75. ->setMethods(['middleware', 'bootstrap'])
  76. ->setConstructorArgs([$this->config])
  77. ->getMock();
  78. $runner = new CommandRunner($app);
  79. $runner->run(['bad', 'i18n']);
  80. }
  81. /**
  82. * Test that running an unknown command raises an error.
  83. *
  84. * @expectedException \RuntimeException
  85. * @expectedExceptionMessage Unknown command `cake nope`. Run `cake --help` to get the list of valid commands.
  86. * @return void
  87. */
  88. public function testRunInvalidCommand()
  89. {
  90. $app = $this->getMockBuilder(BaseApplication::class)
  91. ->setMethods(['middleware', 'bootstrap'])
  92. ->setConstructorArgs([$this->config])
  93. ->getMock();
  94. $runner = new CommandRunner($app);
  95. $runner->run(['cake', 'nope', 'nope', 'nope']);
  96. }
  97. /**
  98. * Test using `cake --help` invokes the help command
  99. *
  100. * @return void
  101. */
  102. public function testRunHelpLongOption()
  103. {
  104. $this->markTestIncomplete();
  105. }
  106. /**
  107. * Test using `cake -h` invokes the help command
  108. *
  109. * @return void
  110. */
  111. public function testRunHelpShortOption()
  112. {
  113. $this->markTestIncomplete();
  114. }
  115. /**
  116. * Test using `cake --verson` invokes the version command
  117. *
  118. * @return void
  119. */
  120. public function testRunVersionLongOption()
  121. {
  122. $this->markTestIncomplete();
  123. }
  124. /**
  125. * Test using `cake -v` invokes the version command
  126. *
  127. * @return void
  128. */
  129. public function testRunVersionShortOption()
  130. {
  131. $this->markTestIncomplete();
  132. }
  133. }