From baf4147d6757b1c1d7de2d4d706d92c23a822142 Mon Sep 17 00:00:00 2001 From: Yves P Date: Wed, 22 Apr 2015 19:56:07 +0200 Subject: [PATCH] Add tests to dispatchShell --- tests/TestCase/Console/ShellTest.php | 93 ++++++++++++++----- .../TestApp/Shell/TestingDispatchShell.php | 69 ++++++++++++++ 2 files changed, 141 insertions(+), 21 deletions(-) diff --git a/tests/TestCase/Console/ShellTest.php b/tests/TestCase/Console/ShellTest.php index 3912238bd3f..342c688a05d 100644 --- a/tests/TestCase/Console/ShellTest.php +++ b/tests/TestCase/Console/ShellTest.php @@ -689,6 +689,78 @@ public function testDispatchShellArgsParser() $this->assertEquals($expected, $result); } + /** + * test calling a shell that dispatch another one + * + * @return void + */ + public function testDispatchShell() + { + $Shell = new TestingDispatchShell(); + ob_start(); + $Shell->runCommand(['test_task'], true); + $result = ob_get_clean(); + + $expected = <<Welcome to CakePHP Console +I am a test task, I dispatch another Shell +I am a dispatched Shell + +TEXT; + $this->assertEquals($expected, $result); + + ob_start(); + $Shell->runCommand(['test_task_dispatch_array'], true); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + + ob_start(); + $Shell->runCommand(['test_task_dispatch_command_string'], true); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + + ob_start(); + $Shell->runCommand(['test_task_dispatch_command_array'], true); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + + $expected = <<Welcome to CakePHP Console +I am a test task, I dispatch another Shell +I am a dispatched Shell. My param `foo` has the value `bar` + +TEXT; + + ob_start(); + $Shell->runCommand(['test_task_dispatch_with_param'], true); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + + $expected = <<Welcome to CakePHP Console +I am a test task, I dispatch another Shell +I am a dispatched Shell. My param `foo` has the value `bar` +My param `fooz` has the value `baz` + +TEXT; + ob_start(); + $Shell->runCommand(['test_task_dispatch_with_multiple_params'], true); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + + $expected = <<Welcome to CakePHP Console +I am a test task, I dispatch another Shell +Welcome to CakePHP Console +I am a dispatched Shell + +TEXT; + ob_start(); + $Shell->runCommand(['test_task_dispatch_with_requested_off'], true); + $result = ob_get_clean(); + $this->assertEquals($expected, $result); + } + /** * Test that runCommand() doesn't call public methods when the second arg is false. * @@ -897,27 +969,6 @@ public function testRunCommandHittingTaskInSubcommand() $shell->runCommand(['slice', 'one']); } - /** - * test calling a shell that dispatch another one - * - * @return void - */ - public function testDispatchShell() - { - $Shell = new TestingDispatchShell(); - ob_start(); - $Shell->runCommand(['test_task'], true); - $result = ob_get_clean(); - - $expected = <<Welcome to CakePHP Console -I am a test task, I dispatch another Shell -I am a dispatched Shell - -TEXT; - $this->assertEquals($expected, $result); - } - /** * test wrapBlock wrapping text. * diff --git a/tests/test_app/TestApp/Shell/TestingDispatchShell.php b/tests/test_app/TestApp/Shell/TestingDispatchShell.php index b7ef3c1adb9..dbddf4db5ae 100644 --- a/tests/test_app/TestApp/Shell/TestingDispatchShell.php +++ b/tests/test_app/TestApp/Shell/TestingDispatchShell.php @@ -36,14 +36,83 @@ public function out($message = null, $newlines = 1, $level = Shell::NORMAL) } public function testTask() + { + $this->out('I am a test task, I dispatch another Shell'); + Configure::write('App.namespace', 'TestApp'); + $this->dispatchShell('testing_dispatch dispatch_test_task'); + } + + public function testTaskDispatchArray() { $this->out('I am a test task, I dispatch another Shell'); Configure::write('App.namespace', 'TestApp'); $this->dispatchShell('testing_dispatch', 'dispatch_test_task'); } + public function testTaskDispatchCommandString() + { + $this->out('I am a test task, I dispatch another Shell'); + Configure::write('App.namespace', 'TestApp'); + $this->dispatchShell(['command' => 'testing_dispatch dispatch_test_task']); + } + + public function testTaskDispatchCommandArray() + { + $this->out('I am a test task, I dispatch another Shell'); + Configure::write('App.namespace', 'TestApp'); + $this->dispatchShell(['command' => ['testing_dispatch', 'dispatch_test_task']]); + } + + public function testTaskDispatchWithParam() + { + $this->out('I am a test task, I dispatch another Shell'); + Configure::write('App.namespace', 'TestApp'); + $this->dispatchShell([ + 'command' => ['testing_dispatch', 'dispatch_test_task_param'], + 'extra' => [ + 'foo' => 'bar' + ] + ]); + } + + public function testTaskDispatchWithMultipleParams() + { + $this->out('I am a test task, I dispatch another Shell'); + Configure::write('App.namespace', 'TestApp'); + $this->dispatchShell([ + 'command' => ['testing_dispatch dispatch_test_task_params'], + 'extra' => [ + 'foo' => 'bar', + 'fooz' => 'baz' + ] + ]); + } + + public function testTaskDispatchWithRequestedOff() + { + $this->out('I am a test task, I dispatch another Shell'); + Configure::write('App.namespace', 'TestApp'); + $this->dispatchShell([ + 'command' => ['testing_dispatch', 'dispatch_test_task'], + 'extra' => [ + 'requested' => false + ] + ]); + } + public function dispatchTestTask() { $this->out('I am a dispatched Shell'); } + + public function dispatchTestTaskParam() + { + $this->out('I am a dispatched Shell. My param `foo` has the value `' . $this->param('foo') . '`'); + } + + public function dispatchTestTaskParams() + { + $this->out('I am a dispatched Shell. My param `foo` has the value `' . $this->param('foo') . '`'); + $this->out('My param `fooz` has the value `' . $this->param('fooz') . '`'); + } }