CommandListShellTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * CommandListShellTest file
  4. *
  5. * CakePHP : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP Project
  14. * @since 2.0.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Console\Command;
  18. use Cake\Console\Command\CommandListShell;
  19. use Cake\Console\Command\Task\CommandTask;
  20. use Cake\Console\ConsoleIo;
  21. use Cake\Console\ConsoleOutput;
  22. use Cake\Core\App;
  23. use Cake\Core\Plugin;
  24. use Cake\TestSuite\TestCase;
  25. /**
  26. * Class TestStringOutput
  27. */
  28. class TestStringOutput extends ConsoleOutput {
  29. public $output = '';
  30. protected function _write($message) {
  31. $this->output .= $message;
  32. }
  33. }
  34. /**
  35. * Class CommandListShellTest
  36. *
  37. */
  38. class CommandListShellTest extends TestCase {
  39. /**
  40. * setUp method
  41. *
  42. * @return void
  43. */
  44. public function setUp() {
  45. parent::setUp();
  46. Plugin::load(array('TestPlugin', 'TestPluginTwo'));
  47. $this->out = new TestStringOutput();
  48. $io = new ConsoleIo($this->out);
  49. $this->Shell = $this->getMock(
  50. 'Cake\Console\Command\CommandListShell',
  51. ['in', 'err', '_stop', 'clear'],
  52. [$io]
  53. );
  54. $this->Shell->Command = $this->getMock(
  55. 'Cake\Console\Command\Task\CommandTask',
  56. ['in', '_stop', 'err', 'clear'],
  57. [$io]
  58. );
  59. }
  60. /**
  61. * tearDown
  62. *
  63. * @return void
  64. */
  65. public function tearDown() {
  66. parent::tearDown();
  67. unset($this->Shell);
  68. Plugin::unload();
  69. }
  70. /**
  71. * test that main finds core shells.
  72. *
  73. * @return void
  74. */
  75. public function testMain() {
  76. $this->Shell->main();
  77. $output = $this->out->output;
  78. $expected = "/\[.*TestPlugin.*\] example/";
  79. $this->assertRegExp($expected, $output);
  80. $expected = "/\[.*TestPluginTwo.*\] example, welcome/";
  81. $this->assertRegExp($expected, $output);
  82. $expected = "/\[.*CORE.*\] bake, i18n, orm_cache, server, test/";
  83. $this->assertRegExp($expected, $output);
  84. $expected = "/\[.*app.*\] sample/";
  85. $this->assertRegExp($expected, $output);
  86. }
  87. /**
  88. * test xml output.
  89. *
  90. * @return void
  91. */
  92. public function testMainXml() {
  93. $this->assertFalse(defined('HHVM_VERSION'), 'Remove when travis updates to hhvm 2.5');
  94. $this->Shell->params['xml'] = true;
  95. $this->Shell->main();
  96. $output = $this->out->output;
  97. $find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
  98. $this->assertContains($find, $output);
  99. $find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
  100. $this->assertContains($find, $output);
  101. $find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
  102. $this->assertContains($find, $output);
  103. }
  104. }