CommandListShellTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * CakePHP : 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 Project
  12. * @since 2.0.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\Configure;
  18. use Cake\Core\Plugin;
  19. use Cake\TestSuite\ConsoleIntegrationTestCase;
  20. /**
  21. * CommandListShellTest
  22. */
  23. class CommandListShellTest extends ConsoleIntegrationTestCase
  24. {
  25. /**
  26. * setUp method
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. Plugin::load(['TestPlugin', 'TestPluginTwo']);
  34. }
  35. /**
  36. * tearDown
  37. *
  38. * @return void
  39. */
  40. public function tearDown()
  41. {
  42. parent::tearDown();
  43. Plugin::unload();
  44. }
  45. /**
  46. * test that main finds core shells.
  47. *
  48. * @return void
  49. */
  50. public function testMain()
  51. {
  52. $this->exec('command_list');
  53. $expected = "/\[.*TestPlugin.*\] example/";
  54. $this->assertOutputRegExp($expected);
  55. $expected = "/\[.*TestPluginTwo.*\] example, unique, welcome/";
  56. $this->assertOutputRegExp($expected);
  57. $expected = "/\[.*CORE.*\] cache, help, i18n, orm_cache, plugin, routes, server/";
  58. $this->assertOutputRegExp($expected);
  59. $expected = "/\[.*app.*\] i18m, integration, sample/";
  60. $this->assertOutputRegExp($expected);
  61. $this->assertExitCode(Shell::CODE_SUCCESS);
  62. $this->assertErrorEmpty();
  63. }
  64. /**
  65. * If there is an app shell with the same name as a core shell,
  66. * tests that the app shell is the one displayed and the core one is hidden.
  67. *
  68. * @return void
  69. */
  70. public function testMainAppPriority()
  71. {
  72. rename(APP . 'Shell' . DS . 'I18mShell.php', APP . 'Shell' . DS . 'I18nShell.php');
  73. $this->exec('command_list');
  74. rename(APP . 'Shell' . DS . 'I18nShell.php', APP . 'Shell' . DS . 'I18mShell.php');
  75. $expected = "/\[.*CORE.*\] cache, help, orm_cache, plugin, routes, server/";
  76. $this->assertOutputRegExp($expected);
  77. $expected = "/\[.*app.*\] i18n, integration, sample/";
  78. $this->assertOutputRegExp($expected);
  79. $this->assertExitCode(Shell::CODE_SUCCESS);
  80. $this->assertErrorEmpty();
  81. }
  82. /**
  83. * test xml output.
  84. *
  85. * @return void
  86. */
  87. public function testMainXml()
  88. {
  89. $this->exec('command_list --xml');
  90. $find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"';
  91. $this->assertOutputContains($find);
  92. $find = '<shell name="orm_cache" call_as="orm_cache" provider="CORE" help="orm_cache -h"';
  93. $this->assertOutputContains($find);
  94. $find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
  95. $this->assertOutputContains($find);
  96. $this->assertExitCode(Shell::CODE_SUCCESS);
  97. $this->assertErrorEmpty();
  98. }
  99. /**
  100. * test that main prints the cakephp's version.
  101. *
  102. * @return void
  103. */
  104. public function testMainVersion()
  105. {
  106. $this->exec('command_list --version');
  107. $expected = Configure::version();
  108. $this->assertOutputContains($expected);
  109. $this->assertExitCode(Shell::CODE_SUCCESS);
  110. $this->assertErrorEmpty();
  111. }
  112. }