Skip to content

Commit

Permalink
[FEATURE] RS-1988 : aoe/tagging library branch switching hinzufügen
Browse files Browse the repository at this point in the history
wenn beim Aufruf des tagging scripts die Option '--switch-branch' zusammen mit einem Branch
angegeben wird, wird innerhalb des Respository auf diesen Branch gewechselt
  • Loading branch information
michael.sandritter committed Sep 8, 2016
1 parent 5580329 commit 603272f
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 66 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"autoload": {
"psr-4": {
"AOE\\Tagging\\": "src/"
"AOE\\Tagging\\": "src/",
"AOE\\Tagging\\Tests\\": "test /"
}
},
"bin": [
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private function getLatestVersion(InputInterface $input, GitDriver $git)
}
}

/**
/**
* @param string $url
* @return GitDriver
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Vcs/Driver/GitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function tag($tag, $branch, $path)
}

/**
* @param $branch
* @param $path
* @param string $branch
* @param string $path
* @param OutputInterface $output
* @throws \Exception
*/
Expand Down
84 changes: 83 additions & 1 deletion test/Command/GitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
namespace AOE\Tagging\Tests\Command;

use AOE\Tagging\Command\GitCommand;
use AOE\Tagging\Tests\TaggingPHPUnitTestCase;
use AOE\Tagging\Vcs\Driver\GitDriver;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @package AOE\Tagging\Tests\Vcs
*/
class GitCommandTest extends \PHPUnit_Framework_TestCase
class GitCommandTest extends TaggingPHPUnitTestCase
{
/**
* @test
Expand Down Expand Up @@ -293,6 +295,43 @@ public function shouldCommitAdditionalFileWithMessage()
);
}

/**
* @test
*/
public function shouldWriteCommitAndPushInfoWithVerbosityVerbose()
{
$gitDriver = $this->getMockBuilder('AOE\\Tagging\\Vcs\\Driver\\GitDriver')
->disableOriginalConstructor()
->setMethods(array('getLatestTag', 'tag', 'hasChangesSinceTag', 'commit'))
->getMock();
$gitDriver->expects($this->once())->method('hasChangesSinceTag')->will($this->returnValue(true));
$gitDriver->expects($this->once())->method('getLatestTag')->will($this->returnValue('2.7.3'));
$gitDriver->expects($this->once())->method('commit')
->with(array('myfile.ext'), '/home/foo/bar', 'my message for commit');
$gitCommand = $this->getMockBuilder('AOE\\Tagging\\Command\\GitCommand')
->setMethods(array('getDriver'))
->getMock();
$gitCommand->expects($this->once())->method('getDriver')->will($this->returnValue($gitDriver));

/** @var GitCommand $gitCommand */
$application = new Application();
$application->add($gitCommand);

$command = $application->find('git');
$commandTester = new CommandTester($command);
$test = $commandTester->getOutput();
$commandTester->execute(
array(
'command' => $command->getName(),
'url' => '[email protected]/foo/bar',
'path' => '/home/foo/bar',
'--commit-and-push' => array('myfile.ext'),
'--message' => 'my message for commit'
),
['verbosity' => 2]
);
}

/**
* @test
*/
Expand Down Expand Up @@ -375,4 +414,47 @@ public function shouldEvaluateVersionNumberIfNoChangesDetected()

$this->assertEmpty($commandTester->getDisplay());
}

/**
* @test
*/
public function shouldCheckoutBranchWithSwitchBranchOptionWhenExecuting()
{
$gitDriver = $this->getMockBuilder('AOE\\Tagging\\Vcs\\Driver\\GitDriver')
->disableOriginalConstructor()
->setMethods(array('checkoutBranch'))
->getMock();

$gitDriver->expects($this->once())->method('checkoutBranch');

$gitCommand = $this->getMockBuilder('AOE\\Tagging\\Command\\GitCommand')
->setMethods(array('getDriver'))
->getMock();
$gitCommand->expects($this->once())->method('getDriver')->will($this->returnValue($gitDriver));

/** @var GitCommand $gitCommand */
$application = new Application();
$application->add($gitCommand);

$command = $application->find('git');
$commandTester = new CommandTester($command);
$commandTester->execute(
array(
'command' => $command->getName(),
'url' => '[email protected]/foo/bar',
'path' => '/home/foo/bar',
'--switch-branch' => null
)
);
}

/**
* @test
*/
public function shouldGetDriver()
{
$gitCommand = new GitCommand();
$driver = $this->invokeMethod($gitCommand, 'getDriver',['https://url']);
$this->assertInstanceOf(GitDriver::class, $driver);
}
}
23 changes: 23 additions & 0 deletions test/TaggingPHPUnitTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace AOE\Tagging\Tests;

class TaggingPHPUnitTestCase extends \PHPUnit_Framework_TestCase
{
/**
* Call protected/private method of a class.
*
* @param object &$object Instantiated object that we will run method on.
* @param string $methodName Method name to call
* @param array $parameters Array of parameters to pass into method.
*
* @return mixed Method return.
*/
protected function invokeMethod(&$object, $methodName, array $parameters = array())
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);

return $method->invokeArgs($object, $parameters);
}
}
Loading

0 comments on commit 603272f

Please sign in to comment.