HelpCommandTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. Plugin::unload();
  36. $app = $this->getMockForAbstractClass(
  37. BaseApplication::class,
  38. ['']
  39. );
  40. $app->addPlugin('TestPlugin');
  41. }
  42. /**
  43. * tearDown
  44. *
  45. * @return void
  46. */
  47. public function tearDown()
  48. {
  49. parent::tearDown();
  50. Plugin::unload();
  51. }
  52. /**
  53. * Test the command listing fallback when no commands are set
  54. *
  55. * @return void
  56. */
  57. public function testMainNoCommandsFallback()
  58. {
  59. $this->exec('help');
  60. $this->assertExitCode(Shell::CODE_SUCCESS);
  61. $this->assertCommandList();
  62. Plugin::unload();
  63. }
  64. /**
  65. * Test the command listing
  66. *
  67. * @return void
  68. */
  69. public function testMain()
  70. {
  71. $this->exec('help');
  72. $this->assertExitCode(Shell::CODE_SUCCESS);
  73. $this->assertCommandList();
  74. }
  75. /**
  76. * Assert the help output.
  77. *
  78. * @return void
  79. */
  80. protected function assertCommandList()
  81. {
  82. $this->assertOutputContains('- widget', 'plugin command');
  83. $this->assertOutputNotContains(
  84. '- test_plugin.widget',
  85. 'only short alias for plugin command.'
  86. );
  87. $this->assertOutputContains('- sample', 'app shell');
  88. $this->assertOutputContains('- test_plugin.sample', 'Long plugin name');
  89. $this->assertOutputContains('- routes', 'core shell');
  90. $this->assertOutputContains('- example', 'short plugin name');
  91. $this->assertOutputContains('- abort', 'command object');
  92. $this->assertOutputContains('To run a command', 'more info present');
  93. $this->assertOutputContains('To get help', 'more info present');
  94. }
  95. /**
  96. * Test help --xml
  97. *
  98. * @return void
  99. */
  100. public function testMainAsXml()
  101. {
  102. $this->exec('help --xml');
  103. $this->assertExitCode(Shell::CODE_SUCCESS);
  104. $this->assertOutputContains('<shells>');
  105. $find = '<shell name="sample" call_as="sample" provider="TestApp\Shell\SampleShell" help="sample -h"';
  106. $this->assertOutputContains($find);
  107. $find = '<shell name="orm_cache" call_as="orm_cache" provider="Cake\Shell\OrmCacheShell" help="orm_cache -h"';
  108. $this->assertOutputContains($find);
  109. $find = '<shell name="test_plugin.sample" call_as="test_plugin.sample" provider="TestPlugin\Shell\SampleShell" help="test_plugin.sample -h"';
  110. $this->assertOutputContains($find);
  111. }
  112. }