Skip to content

Commit

Permalink
Added parents command
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 committed Sep 14, 2014
1 parent 0980e61 commit f3c9cef
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/Command/ParentsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* VersionControl_HG
* Simple OO implementation for Mercurial.
*
* PHP Version 5.4
*
* @copyright 2014 Siad Ardroumli
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://siad007.github.io/versioncontrol_hg
*/

namespace Siad007\VersionControl\HG\Command;

/**
* Simple OO implementation for Mercurial.
*
* @author Siad Ardroumli <[email protected]>
*
* @method string getRev()
* @method void setRev(string $revision)
* @method string getTemplate()
* @method void setTemplate(string $template)
*/
class ParentsCommand extends AbstractCommand
{
/**
* Available arguments for this command.
*
* @var array $arguments
*/
protected $arguments = array(
'file' => ''
);

/**
* {@inheritdoc}
*
* @var mixed $options
*/
protected $options = array(
'--rev' => '',
'--template' => ''
);

/**
* @return string
*/
public function getFile()
{
return $this->arguments['file'];
}

/**
* @param string $file
*
* @return void
*/
public function setFile($file)
{
$this->arguments['file'] = escapeshellarg($file);
}

/**
* {@inheritdoc}
*/
public function __toString()
{
return sprintf(
"%s%s %s",
$this->name,
$this->assembleOptionString(),
$this->arguments['file']
);
}
}
1 change: 1 addition & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @method \Siad007\VersionControl\HG\Command\ManifestCommand createManifest(array $options = array)
* @method \Siad007\VersionControl\HG\Command\MergeCommand createMerge(array $options = array)
* @method \Siad007\VersionControl\HG\Command\PathsCommand createPaths(array $options = array)
* @method \Siad007\VersionControl\HG\Command\ParentsCommand createParents(array $options = array)
* @method \Siad007\VersionControl\HG\Command\PullCommand createPull(array $options = array)
* @method \Siad007\VersionControl\HG\Command\PushCommand createPush(array $options = array)
* @method \Siad007\VersionControl\HG\Command\RecoverCommand createRecover(array $options = array)
Expand Down
39 changes: 39 additions & 0 deletions tests/Command/ParentsCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* VersionControl_HG
* Simple OO implementation for Mercurial.
*
* PHP Version 5.4
*
* @copyright 2014 Siad Ardroumli
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://siad007.github.io/versioncontrol_hg
*/

namespace Siad007\VersionControl\HG\Tests\Command;

use Siad007\VersionControl\HG\Factory;

class ParentsCommandTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function parentsCommand()
{
$parentsCmd = Factory::createParents();
$parentsCmd->setFile('C:\\xampp\\file\\');
$parentsCmd->setRev('revision');
$parentsCmd->setTemplate('template');

$file = '\'C:\xampp\file\\\'';
$expected = 'hg parents --rev revision --template template ';

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$file = str_replace("'", '"', $file);
}

$this->assertSame($file, $parentsCmd->getFile());
$this->assertSame($expected . $file, $parentsCmd->asString());
}
}

0 comments on commit f3c9cef

Please sign in to comment.