HelpCommandTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * HelpShell test.
  21. */
  22. class HelpShellTest 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. Plugin::load('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. }
  47. /**
  48. * Test the command listing
  49. *
  50. * @return void
  51. */
  52. public function testMain()
  53. {
  54. $this->exec('help');
  55. $this->assertExitCode(Shell::CODE_SUCCESS);
  56. $this->assertCommandList();
  57. }
  58. /**
  59. * Assert the help output.
  60. *
  61. * @param string $output The output to check.
  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('To run a command', 'more info present');
  76. $this->assertOutputContains('To get help', 'more info present');
  77. }
  78. /**
  79. * Test help --xml
  80. *
  81. * @return void
  82. */
  83. public function testMainAsXml()
  84. {
  85. $this->exec('help --xml');
  86. $this->assertExitCode(Shell::CODE_SUCCESS);
  87. $this->assertOutputContains('<shells>');
  88. $find = '<shell name="sample" call_as="sample" provider="TestApp\Shell\SampleShell" help="sample -h"';
  89. $this->assertOutputContains($find);
  90. $find = '<shell name="orm_cache" call_as="orm_cache" provider="Cake\Shell\OrmCacheShell" help="orm_cache -h"';
  91. $this->assertOutputContains($find);
  92. $find = '<shell name="test_plugin.sample" call_as="test_plugin.sample" provider="TestPlugin\Shell\SampleShell" help="test_plugin.sample -h"';
  93. $this->assertOutputContains($find);
  94. }
  95. }