Add some fixes and tests.

This commit is contained in:
Anton Medvedev 2015-02-18 14:49:21 +03:00
parent c27c82fb93
commit 29a07216ca
4 changed files with 154 additions and 38 deletions

View File

@ -0,0 +1,59 @@
<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Console\Output;
use Symfony\Component\Console\Output\OutputInterface;
class VerbosityString
{
/**
* @var OutputInterface
*/
private $output;
/**
* @param OutputInterface $output
*/
public function __construct(OutputInterface $output)
{
$this->output = $output;
}
/**
* @return string
*/
public function __toString()
{
switch ($this->output->getVerbosity()) {
case OutputInterface::VERBOSITY_NORMAL:
$verbosity = '';
break;
case OutputInterface::VERBOSITY_VERBOSE:
$verbosity = '-v';
break;
case OutputInterface::VERBOSITY_VERY_VERBOSE:
$verbosity = '-vv';
break;
case OutputInterface::VERBOSITY_DEBUG:
$verbosity = '-vvv';
break;
case OutputInterface::VERBOSITY_QUIET:
$verbosity = '-q';
break;
default:
$verbosity = '';
}
return $verbosity;
}
}

View File

@ -8,12 +8,14 @@
namespace Deployer\Executor; namespace Deployer\Executor;
use Deployer\Console\Output\OutputWatcher; use Deployer\Console\Output\OutputWatcher;
use Deployer\Console\Output\VerbosityString;
use Deployer\Task\Context; use Deployer\Task\Context;
use Deployer\Task\NonFatalException; use Deployer\Task\NonFatalException;
use Pure\Server; use Pure\Server;
use Pure\Storage\ArrayStorage; use Pure\Storage\ArrayStorage;
use Pure\Storage\QueueStorage; use Pure\Storage\QueueStorage;
use React\Socket\ConnectionException; use React\Socket\ConnectionException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
@ -48,7 +50,7 @@ class ParallelExecutor implements ExecutorInterface
$hasNonFatalException = false; $hasNonFatalException = false;
// Get verbosity. // Get verbosity.
$verbosity = $this->getVerbosityString($output); $verbosity = new VerbosityString($output);
// Get current deploy.php file. // Get current deploy.php file.
$deployPhpFile = $input->getOption('file'); $deployPhpFile = $input->getOption('file');
@ -61,12 +63,15 @@ class ParallelExecutor implements ExecutorInterface
$deployPhpFile $deployPhpFile
) { ) {
foreach ($servers as $serverName => $server) { foreach ($servers as $serverName => $server) {
$workerInput = new ArrayInput([
'--master' => "127.0.0.1:$port",
'--server' => $serverName,
]);
$process = new Process( $process = new Process(
"php " . DEPLOYER_BIN . "php " . DEPLOYER_BIN .
(null === $deployPhpFile ? "" : " --file=$deployPhpFile") . (null === $deployPhpFile ? "" : " --file=$deployPhpFile") .
" worker" . " worker $workerInput" .
" --master=127.0.0.1:$port" .
" --server=$serverName" .
" $verbosity" . " $verbosity" .
" &" " &"
); );
@ -219,38 +224,4 @@ class ParallelExecutor implements ExecutorInterface
goto start; goto start;
} }
} }
/**
* @param OutputInterface $output
* @return string
*/
private function getVerbosityString(OutputInterface $output)
{
switch ($output->getVerbosity()) {
case OutputInterface::VERBOSITY_NORMAL:
$verbosity = '';
break;
case OutputInterface::VERBOSITY_VERBOSE:
$verbosity = '-v';
break;
case OutputInterface::VERBOSITY_VERY_VERBOSE:
$verbosity = '-vv';
break;
case OutputInterface::VERBOSITY_DEBUG:
$verbosity = '-vvv';
break;
case OutputInterface::VERBOSITY_QUIET:
$verbosity = '-q';
break;
default:
$verbosity = '';
}
return $verbosity;
}
} }

View File

@ -0,0 +1,39 @@
<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Console\Output;
use Symfony\Component\Console\Output\OutputInterface;
class VerbosityStringTest extends \PHPUnit_Framework_TestCase
{
public function verbosity()
{
return [
['-vvv', OutputInterface::VERBOSITY_DEBUG],
['-vv', OutputInterface::VERBOSITY_VERY_VERBOSE],
['-v', OutputInterface::VERBOSITY_VERBOSE],
['', OutputInterface::VERBOSITY_NORMAL],
['-q', OutputInterface::VERBOSITY_QUIET],
];
}
/**
* @dataProvider verbosity
*/
public function testToString($string, $value)
{
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output->expects($this->once())
->method('getVerbosity')
->will($this->returnValue($value));
$verbosity = new VerbosityString($output);
$this->assertEquals($string, (string)$verbosity);
}
}

View File

@ -0,0 +1,47 @@
<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Type;
class ResultTest extends \PHPUnit_Framework_TestCase
{
public function testGetOutput()
{
$result = new Result("str\n");
$this->assertEquals("str\n", $result->getOutput());
}
public function testToString()
{
$result = new Result("str\n");
$this->assertEquals('str', (string)$result);
}
public function testToBool()
{
$result = new Result("true\n");
$this->assertTrue($result->toBool());
$result = new Result("false\n");
$this->assertFalse($result->toBool());
$result = new Result("not-true");
$this->assertFalse($result->toBool());
}
public function testArray()
{
$result = new Result("1\n2\n3\n");
$this->assertEquals([1, 2, 3], $result->toArray());
}
}