TestingDispatchShell.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Testing Dispatch Shell Shell file
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  13. * @link https://cakephp.org CakePHP(tm) Project
  14. * @since 1.2.0
  15. * @license https://opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace TestApp\Shell;
  18. use Cake\Console\Shell;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * for testing dispatchShell functionality
  22. */
  23. class TestingDispatchShell extends Shell
  24. {
  25. protected function _welcome()
  26. {
  27. $this->out('<info>Welcome to CakePHP Console</info>');
  28. }
  29. public function out($message = null, $newlines = 1, $level = Shell::NORMAL)
  30. {
  31. echo $message . "\n";
  32. }
  33. public function testTask()
  34. {
  35. $this->out('I am a test task, I dispatch another Shell');
  36. TestCase::setAppNamespace();
  37. $this->dispatchShell('testing_dispatch dispatch_test_task');
  38. }
  39. public function testTaskDispatchArray()
  40. {
  41. $this->out('I am a test task, I dispatch another Shell');
  42. TestCase::setAppNamespace();
  43. $this->dispatchShell('testing_dispatch', 'dispatch_test_task');
  44. }
  45. public function testTaskDispatchCommandString()
  46. {
  47. $this->out('I am a test task, I dispatch another Shell');
  48. TestCase::setAppNamespace();
  49. $this->dispatchShell(['command' => 'testing_dispatch dispatch_test_task']);
  50. }
  51. public function testTaskDispatchCommandArray()
  52. {
  53. $this->out('I am a test task, I dispatch another Shell');
  54. TestCase::setAppNamespace();
  55. $this->dispatchShell(['command' => ['testing_dispatch', 'dispatch_test_task']]);
  56. }
  57. public function testTaskDispatchWithParam()
  58. {
  59. $this->out('I am a test task, I dispatch another Shell');
  60. TestCase::setAppNamespace();
  61. $this->dispatchShell([
  62. 'command' => ['testing_dispatch', 'dispatch_test_task_param'],
  63. 'extra' => [
  64. 'foo' => 'bar',
  65. ],
  66. ]);
  67. }
  68. public function testTaskDispatchWithMultipleParams()
  69. {
  70. $this->out('I am a test task, I dispatch another Shell');
  71. TestCase::setAppNamespace();
  72. $this->dispatchShell([
  73. 'command' => 'testing_dispatch dispatch_test_task_params',
  74. 'extra' => [
  75. 'foo' => 'bar',
  76. 'fooz' => 'baz',
  77. ],
  78. ]);
  79. }
  80. public function testTaskDispatchWithRequestedOff()
  81. {
  82. $this->out('I am a test task, I dispatch another Shell');
  83. TestCase::setAppNamespace();
  84. $this->dispatchShell([
  85. 'command' => ['testing_dispatch', 'dispatch_test_task'],
  86. 'extra' => [
  87. 'requested' => false,
  88. ],
  89. ]);
  90. }
  91. public function dispatchTestTask()
  92. {
  93. $this->out('I am a dispatched Shell');
  94. }
  95. public function dispatchTestTaskParam()
  96. {
  97. $this->out('I am a dispatched Shell. My param `foo` has the value `' . $this->param('foo') . '`');
  98. }
  99. public function dispatchTestTaskParams()
  100. {
  101. $this->out('I am a dispatched Shell. My param `foo` has the value `' . $this->param('foo') . '`');
  102. $this->out('My param `fooz` has the value `' . $this->param('fooz') . '`');
  103. }
  104. }