Skip to content

Commit

Permalink
GitCommand - drop useless tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Oct 14, 2017
1 parent 66669f9 commit c374c39
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 109 deletions.
Expand Up @@ -79,7 +79,7 @@ protected function configure()
'coverage_clover',
'-x',
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Coverage clover xml files(allowing multiple values).',
'Coverage clover xml files (allowing multiple values).',
array()
)
->addOption(
Expand Down
24 changes: 14 additions & 10 deletions src/Satooshi/Component/System/Git/GitCommand.php
Expand Up @@ -3,6 +3,8 @@
namespace Satooshi\Component\System\Git;

use Satooshi\Component\System\SystemCommand;
use Satooshi\Component\System\SystemCommandExecutor;
use Satooshi\Component\System\SystemCommandExecutorInterface;

/**
* Git command.
Expand All @@ -11,14 +13,22 @@
*/
class GitCommand extends SystemCommand
{
/**
* @var SystemCommandExecutorInterface
*/
private $executor;

/**
* Command name or path.
*
* @var string
*/
protected $commandPath = 'git';

// API
public function __construct(SystemCommandExecutorInterface $executor = null)
{
$this->executor = $executor ? $executor : new SystemCommandExecutor();
}

/**
* Return branch names.
Expand All @@ -27,9 +37,7 @@ class GitCommand extends SystemCommand
*/
public function getBranches()
{
$command = $this->createCommand('branch');

return $this->executeCommand($command);
return $this->executor->execute('git branch');
}

/**
Expand All @@ -39,9 +47,7 @@ public function getBranches()
*/
public function getHeadCommit()
{
$command = $this->createCommand("log -1 --pretty=format:'%H%n%aN%n%ae%n%cN%n%ce%n%s'");

return $this->executeCommand($command);
return $this->executor->execute("git log -1 --pretty=format:'%H%n%aN%n%ae%n%cN%n%ce%n%s'");
}

/**
Expand All @@ -51,8 +57,6 @@ public function getHeadCommit()
*/
public function getRemotes()
{
$command = $this->createCommand('remote -v');

return $this->executeCommand($command);
return $this->executor->execute('git remote -v');
}
}
32 changes: 32 additions & 0 deletions src/Satooshi/Component/System/SystemCommandExecutor.php
@@ -0,0 +1,32 @@
<?php

namespace Satooshi\Component\System;

/**
* @author Kitamura Satoshi <with.no.parachute@gmail.com>
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* @internal
*/
final class SystemCommandExecutor implements SystemCommandExecutorInterface
{
/**
* Execute command.
*
* @param string $command
*
* @throws \RuntimeException
*
* @return array
*/
public function execute($command)
{
exec($command, $result, $returnValue);

if ($returnValue === 0) {
return $result;
}

throw new \RuntimeException(sprintf('Failed to execute command: %s', $command), $returnValue);
}
}
22 changes: 22 additions & 0 deletions src/Satooshi/Component/System/SystemCommandExecutorInterface.php
@@ -0,0 +1,22 @@
<?php

namespace Satooshi\Component\System;

/**
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* @internal
*/
interface SystemCommandExecutorInterface
{
/**
* Execute command.
*
* @param string $command
*
* @throws \RuntimeException
*
* @return array
*/
public function execute($command);
}
Expand Up @@ -62,18 +62,20 @@ public function shouldLoadNonExistingYml()
$this->assertConfiguration($config, array($this->cloverXmlPath), $this->jsonPath);
}

// default src_dir not found, it doesn't throw anything now.
// default src_dir not found, it doesn't throw anything now, as src_dir is not required for configuration

/**
* @test
*/
public function throwInvalidConfigurationExceptionOnLoadEmptyYmlIfSrcDirNotFound()
public function loadConfigurationOnLoadEmptyYmlWhenSrcDirNotFound()
{
$this->makeProjectDir(null, $this->logsDir, $this->cloverXmlPath);

$path = realpath(__DIR__ . '/yaml/dummy.yml');

$this->object->load($path, $this->rootDir);
$config = $this->object->load($path, $this->rootDir);

$this->assertInstanceOf('Satooshi\Bundle\CoverallsV1Bundle\Config\Configuration', $config);
}

// default coverage_clover not found
Expand Down
95 changes: 0 additions & 95 deletions tests/Satooshi/Component/System/Git/GitCommandTest.php
Expand Up @@ -10,56 +10,6 @@
*/
class GitCommandTest extends \PHPUnit\Framework\TestCase
{
protected function createGitCommandMock($params)
{
$adapter = $this->prophesize('Satooshi\Component\System\Git\GitCommand');

$adapter
->executeCommand(\Prophecy\Argument::type('string'));

$adapter
->getBranches()
->willReturn(array());

$adapter
->getRemotes()
->willReturn(array());

$adapter
->getHeadCommit()
->willReturn('asd');

return $adapter->reveal();
}

// getCommandPath()

/**
* @test
*/
public function shouldBeGitCommand()
{
$object = new GitCommand();

$expected = 'git';

$this->assertSame($expected, $object->getCommandPath());
}

// getBranches()
//

/**
* @test
*/
public function shouldExecuteGitBranchCommand()
{
$expected = 'git branch';

$object = $this->createGitCommandMock($expected);
$object->getBranches();
}

/**
* @test
*/
Expand All @@ -72,19 +22,6 @@ public function shouldReturnBranches()
$this->assertNotEmpty($actual);
}

// getHeadCommit()

/**
* @test
*/
public function shouldExecuteGitLogCommand()
{
$expected = "git log -1 --pretty=format:'%H%n%aN%n%ae%n%cN%n%ce%n%s'";

$object = $this->createGitCommandMock($expected);
$object->getHeadCommit();
}

/**
* @test
*/
Expand All @@ -98,19 +35,6 @@ public function shouldReturnHeadCommit()
$this->assertCount(6, $actual);
}

// getRemotes()

/**
* @test
*/
public function shouldExecuteGitRemoteCommand()
{
$expected = 'git remote -v';

$object = $this->createGitCommandMock($expected);
$object->getRemotes();
}

/**
* @test
*/
Expand All @@ -123,32 +47,13 @@ public function shouldReturnRemotes()
$this->assertNotEmpty($actual);
}

// execute()

/**
* @test
* @expectedException \RuntimeException
*/
public function throwRuntimeExceptionIfExecutedWithoutArgs()
{
// `git` return 1 and cause RuntimeException
$object = new GitCommand();
$object->execute();
}

// createCommand()

/**
* @test
*/
public function shouldCreateCommand()
{
$object = new GitCommand();
$object->setCommandPath('ls');

$actual = $object->execute();

$this->assertInternalType('array', $actual);
$this->assertNotEmpty($actual);
}
}

0 comments on commit c374c39

Please sign in to comment.