HelpCommandTest.php 3.5 KB

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