HelpCommandTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\TestSuite\ConsoleIntegrationTestCase;
  19. /**
  20. * HelpCommand test.
  21. */
  22. class HelpCommandTest extends ConsoleIntegrationTestCase
  23. {
  24. /**
  25. * setup method
  26. *
  27. * @return void
  28. */
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. $this->setAppNamespace();
  33. $this->useCommandRunner(true);
  34. $this->loadPlugins('TestPlugin');
  35. }
  36. /**
  37. * Test the command listing fallback when no commands are set
  38. *
  39. * @return void
  40. */
  41. public function testMainNoCommandsFallback()
  42. {
  43. $this->exec('help');
  44. $this->assertExitCode(Shell::CODE_SUCCESS);
  45. $this->assertCommandList();
  46. Plugin::unload();
  47. }
  48. /**
  49. * Test the command listing
  50. *
  51. * @return void
  52. */
  53. public function testMain()
  54. {
  55. $this->exec('help');
  56. $this->assertExitCode(Shell::CODE_SUCCESS);
  57. $this->assertCommandList();
  58. }
  59. /**
  60. * Assert the help output.
  61. *
  62. * @return void
  63. */
  64. protected function assertCommandList()
  65. {
  66. $this->assertOutputContains('- widget', 'plugin command');
  67. $this->assertOutputNotContains(
  68. '- test_plugin.widget',
  69. 'only short alias for plugin command.'
  70. );
  71. $this->assertOutputContains('- sample', 'app shell');
  72. $this->assertOutputContains('- test_plugin.sample', 'Long plugin name');
  73. $this->assertOutputContains('- routes', 'core shell');
  74. $this->assertOutputContains('- example', 'short plugin name');
  75. $this->assertOutputContains('- abort', 'command object');
  76. $this->assertOutputContains('To run a command', 'more info present');
  77. $this->assertOutputContains('To get help', 'more info present');
  78. }
  79. /**
  80. * Test help --xml
  81. *
  82. * @return void
  83. */
  84. public function testMainAsXml()
  85. {
  86. $this->exec('help --xml');
  87. $this->assertExitCode(Shell::CODE_SUCCESS);
  88. $this->assertOutputContains('<shells>');
  89. $find = '<shell name="sample" call_as="sample" provider="TestApp\Shell\SampleShell" help="sample -h"';
  90. $this->assertOutputContains($find);
  91. $find = '<shell name="orm_cache" call_as="orm_cache" provider="Cake\Shell\OrmCacheShell" help="orm_cache -h"';
  92. $this->assertOutputContains($find);
  93. $find = '<shell name="test_plugin.sample" call_as="test_plugin.sample" provider="TestPlugin\Shell\SampleShell" help="test_plugin.sample -h"';
  94. $this->assertOutputContains($find);
  95. }
  96. }