TestingDispatchShell.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /**
  31. * @inheritDoc
  32. */
  33. public function out($message = null, int $newlines = 1, int $level = Shell::NORMAL): ?int
  34. {
  35. echo $message . "\n";
  36. return 1;
  37. }
  38. public function testTask(): void
  39. {
  40. $this->out('I am a test task, I dispatch another Shell');
  41. TestCase::setAppNamespace();
  42. $this->dispatchShell('testing_dispatch dispatch_test_task');
  43. }
  44. public function testTaskDispatchArray(): void
  45. {
  46. $this->out('I am a test task, I dispatch another Shell');
  47. TestCase::setAppNamespace();
  48. $this->dispatchShell('testing_dispatch', 'dispatch_test_task');
  49. }
  50. public function testTaskDispatchCommandString(): void
  51. {
  52. $this->out('I am a test task, I dispatch another Shell');
  53. TestCase::setAppNamespace();
  54. $this->dispatchShell(['command' => 'testing_dispatch dispatch_test_task']);
  55. }
  56. public function testTaskDispatchCommandArray(): void
  57. {
  58. $this->out('I am a test task, I dispatch another Shell');
  59. TestCase::setAppNamespace();
  60. $this->dispatchShell(['command' => ['testing_dispatch', 'dispatch_test_task']]);
  61. }
  62. public function testTaskDispatchWithParam(): void
  63. {
  64. $this->out('I am a test task, I dispatch another Shell');
  65. TestCase::setAppNamespace();
  66. $this->dispatchShell([
  67. 'command' => ['testing_dispatch', 'dispatch_test_task_param'],
  68. 'extra' => [
  69. 'foo' => 'bar',
  70. ],
  71. ]);
  72. }
  73. public function testTaskDispatchWithMultipleParams(): void
  74. {
  75. $this->out('I am a test task, I dispatch another Shell');
  76. TestCase::setAppNamespace();
  77. $this->dispatchShell([
  78. 'command' => 'testing_dispatch dispatch_test_task_params',
  79. 'extra' => [
  80. 'foo' => 'bar',
  81. 'fooz' => 'baz',
  82. ],
  83. ]);
  84. }
  85. public function testTaskDispatchWithRequestedOff(): void
  86. {
  87. $this->out('I am a test task, I dispatch another Shell');
  88. TestCase::setAppNamespace();
  89. $this->dispatchShell([
  90. 'command' => ['testing_dispatch', 'dispatch_test_task'],
  91. 'extra' => [
  92. 'requested' => false,
  93. ],
  94. ]);
  95. }
  96. public function dispatchTestTask(): void
  97. {
  98. $this->out('I am a dispatched Shell');
  99. }
  100. public function dispatchTestTaskParam(): void
  101. {
  102. $this->out('I am a dispatched Shell. My param `foo` has the value `' . $this->param('foo') . '`');
  103. }
  104. public function dispatchTestTaskParams(): void
  105. {
  106. $this->out('I am a dispatched Shell. My param `foo` has the value `' . $this->param('foo') . '`');
  107. $this->out('My param `fooz` has the value `' . $this->param('fooz') . '`');
  108. }
  109. }