Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kohkimakimoto committed Oct 28, 2014
1 parent ef9508e commit 8c8cbc7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
29 changes: 0 additions & 29 deletions src/Altax/Task/TaskManager.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Altax\Task;

use Symfony\Component\Console\Input\ArrayInput;

/**
* TaskManager
*/
Expand Down Expand Up @@ -59,31 +57,4 @@ public function getTask($name, $default = null)
return isset($this->tasks[$name]) ? $this->tasks[$name] : $default;
}

public function call($name, $inputArguments = array())
{
$arguments = array();
if ($this->output->isDebug()) {
$this->output->writeln("Calling task: ".$name);
}

$command = $this->console->get($name);

$definition = $command->getDefinition();
$commandArguments = $definition->getArguments();

if (is_vector($inputArguments)) {
foreach ($commandArguments as $key => $commandArgument) {
if ($key === "command") {
continue;
}
$arguments[$key] = array_shift($inputArguments);
}
} else {
$arguments = $inputArguments;
}
$arguments['command'] = $name;
$input = new ArrayInput($arguments);

return $command->run($input, $this->output);
}
}
23 changes: 23 additions & 0 deletions tests/Altax/Shell/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,27 @@ public function testRunOnSubprocess()

$this->assertRegExp("/Run command: pwd on 127.0.0.1/", $this->app['output']->fetch());
}

public function testRunOnSubprocessWithOptions()
{
$servers = $this->app['servers'];
$servers->node("127.0.0.1");
$env = $this->app['env'];
$env->set('process.parallel', false);

$executor = $this->app['process.executor'];
$executor->on(["127.0.0.1"], function(){

$commandBuilder = $this->app["shell.command"];
$commandBuilder->run("pwd", [
"cwd" => __DIR__,
"user" => get_current_user(),
"timeout" => 100,
]);

});

$this->assertRegExp("/Run command: pwd on 127.0.0.1/", $this->app['output']->fetch());
}

}
6 changes: 6 additions & 0 deletions tests/Altax/Shell/ShellServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Test\Altax\Shell;

use Altax\Shell\CommandBuilder;
use Altax\Shell\LocalCommandBuilder;

class ShellServiceProviderTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -16,4 +17,9 @@ public function testCommandBuilder()
$this->assertTrue($obj instanceof CommandBuilder);
}

public function testLocalCommandBuilder()
{
$obj = $this->app["shell.local_command"];
$this->assertTrue($obj instanceof LocalCommandBuilder);
}
}

0 comments on commit 8c8cbc7

Please sign in to comment.