HelpShellTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Shell;
  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('- sample', 'app shell');
  67. $this->assertOutputContains('- test_plugin.sample', 'Long plugin name');
  68. $this->assertOutputContains('- routes', 'core shell');
  69. $this->assertOutputContains('- test_plugin.example', 'Long plugin name');
  70. $this->assertOutputContains('To run a command', 'more info present');
  71. $this->assertOutputContains('To get help', 'more info present');
  72. }
  73. /**
  74. * Test help --xml
  75. *
  76. * @return void
  77. */
  78. public function testMainAsXml()
  79. {
  80. $this->exec('help --xml');
  81. $this->assertExitCode(Shell::CODE_SUCCESS);
  82. $this->assertOutputContains('<shells>');
  83. $find = '<shell name="sample" call_as="sample" provider="TestApp\Shell\SampleShell" help="sample -h"';
  84. $this->assertOutputContains($find);
  85. $find = '<shell name="orm_cache" call_as="orm_cache" provider="Cake\Shell\OrmCacheShell" help="orm_cache -h"';
  86. $this->assertOutputContains($find);
  87. $find = '<shell name="test_plugin.sample" call_as="test_plugin.sample" provider="TestPlugin\Shell\SampleShell" help="test_plugin.sample -h"';
  88. $this->assertOutputContains($find);
  89. }
  90. }