Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests to dispatchShell
  • Loading branch information
HavokInspiration committed Apr 22, 2015
1 parent bc35e7b commit baf4147
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 21 deletions.
93 changes: 72 additions & 21 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -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 = <<<TEXT
<info>Welcome to CakePHP Console</info>
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 = <<<TEXT
<info>Welcome to CakePHP Console</info>
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 = <<<TEXT
<info>Welcome to CakePHP Console</info>
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 = <<<TEXT
<info>Welcome to CakePHP Console</info>
I am a test task, I dispatch another Shell
<info>Welcome to CakePHP Console</info>
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.
*
Expand Down Expand Up @@ -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 = <<<TEXT
<info>Welcome to CakePHP Console</info>
I am a test task, I dispatch another Shell
I am a dispatched Shell
TEXT;
$this->assertEquals($expected, $result);
}

/**
* test wrapBlock wrapping text.
*
Expand Down
69 changes: 69 additions & 0 deletions tests/test_app/TestApp/Shell/TestingDispatchShell.php
Expand Up @@ -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') . '`');
}
}

0 comments on commit baf4147

Please sign in to comment.