HelpCommandTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.5.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Command;
  16. use Cake\Console\Shell;
  17. use Cake\Core\Plugin;
  18. use Cake\Http\BaseApplication;
  19. use Cake\TestSuite\ConsoleIntegrationTestCase;
  20. /**
  21. * HelpCommand test.
  22. */
  23. class HelpCommandTest extends ConsoleIntegrationTestCase
  24. {
  25. /**
  26. * setup method
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. $this->setAppNamespace();
  34. $this->useCommandRunner(true);
  35. $app = $this->getMockForAbstractClass(
  36. BaseApplication::class,
  37. ['']
  38. );
  39. $app->addPlugin('TestPlugin');
  40. }
  41. /**
  42. * tearDown
  43. *
  44. * @return void
  45. */
  46. public function tearDown()
  47. {
  48. parent::tearDown();
  49. $this->clearPlugins();
  50. }
  51. /**
  52. * Test the command listing fallback when no commands are set
  53. *
  54. * @return void
  55. */
  56. public function testMainNoCommandsFallback()
  57. {
  58. $this->exec('help');
  59. $this->assertExitCode(Shell::CODE_SUCCESS);
  60. $this->assertCommandList();
  61. $this->clearPlugins();
  62. }
  63. /**
  64. * Test the command listing
  65. *
  66. * @return void
  67. */
  68. public function testMain()
  69. {
  70. $this->exec('help');
  71. $this->assertExitCode(Shell::CODE_SUCCESS);
  72. $this->assertCommandList();
  73. }
  74. /**
  75. * Assert the help output.
  76. *
  77. * @return void
  78. */
  79. protected function assertCommandList()
  80. {
  81. $this->assertOutputContains('- widget', 'plugin command');
  82. $this->assertOutputNotContains(
  83. '- test_plugin.widget',
  84. 'only short alias for plugin command.'
  85. );
  86. $this->assertOutputContains('- sample', 'app shell');
  87. $this->assertOutputContains('- routes', 'core shell');
  88. $this->assertOutputContains('- example', 'short plugin name');
  89. $this->assertOutputContains('- abort', 'command object');
  90. $this->assertOutputContains('To run a command', 'more info present');
  91. $this->assertOutputContains('To get help', 'more info present');
  92. }
  93. /**
  94. * Test help --xml
  95. *
  96. * @return void
  97. */
  98. public function testMainAsXml()
  99. {
  100. $this->exec('help --xml');
  101. $this->assertExitCode(Shell::CODE_SUCCESS);
  102. $this->assertOutputContains('<shells>');
  103. $find = '<shell name="sample" call_as="sample" provider="TestApp\Shell\SampleShell" help="sample -h"';
  104. $this->assertOutputContains($find);
  105. $find = '<shell name="orm_cache" call_as="orm_cache" provider="Cake\Shell\OrmCacheShell" help="orm_cache -h"';
  106. $this->assertOutputContains($find);
  107. $find = '<shell name="test_plugin.sample" call_as="test_plugin.sample" provider="TestPlugin\Shell\SampleShell" help="test_plugin.sample -h"';
  108. $this->assertOutputContains($find);
  109. }
  110. }