From f3c9cef87b8672d39597e9c7b1fb19453d4ee957 Mon Sep 17 00:00:00 2001 From: siad007 Date: Mon, 15 Sep 2014 00:34:14 +0200 Subject: [PATCH] Added parents command --- src/Command/ParentsCommand.php | 76 ++++++++++++++++++++++++++++ src/Factory.php | 1 + tests/Command/ParentsCommandTest.php | 39 ++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/Command/ParentsCommand.php create mode 100644 tests/Command/ParentsCommandTest.php diff --git a/src/Command/ParentsCommand.php b/src/Command/ParentsCommand.php new file mode 100644 index 0000000..a0a9576 --- /dev/null +++ b/src/Command/ParentsCommand.php @@ -0,0 +1,76 @@ + + * + * @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'] + ); + } +} diff --git a/src/Factory.php b/src/Factory.php index b250509..c39b92e 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -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) diff --git a/tests/Command/ParentsCommandTest.php b/tests/Command/ParentsCommandTest.php new file mode 100644 index 0000000..4828d53 --- /dev/null +++ b/tests/Command/ParentsCommandTest.php @@ -0,0 +1,39 @@ +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()); + } +}