TestingDispatchShell.php 3.6 KB

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