diff --git a/docs/commands/add.rst b/docs/commands/add.rst index bf99047..015323d 100644 --- a/docs/commands/add.rst +++ b/docs/commands/add.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $addCmd = Factory::createAdd(); - $addCmd->run(); + $addCmd->execute(); diff --git a/docs/commands/addremove.rst b/docs/commands/addremove.rst index 5fb890e..28056ca 100644 --- a/docs/commands/addremove.rst +++ b/docs/commands/addremove.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $addremoveCmd = Factory::createAddremove(); - $addremoveCmd->run(); + $addremoveCmd->execute(); diff --git a/docs/commands/archive.rst b/docs/commands/archive.rst index fb80a9a..19c831a 100644 --- a/docs/commands/archive.rst +++ b/docs/commands/archive.rst @@ -16,4 +16,4 @@ Examples: $archiveCmd->addExclude('excludePattern'); $archiveCmd->setSubrepos(tru); $archiveCmd->setNoDecode(true); - + $archiveCmd->execute(); diff --git a/docs/commands/bundle.rst b/docs/commands/bundle.rst index c55d012..04b93d1 100644 --- a/docs/commands/bundle.rst +++ b/docs/commands/bundle.rst @@ -16,5 +16,5 @@ Examples: $bundleCmd->setInsecure(true); $bundleCmd->setVerbose(true); $bundleCmd->setEncoding('UTF-8'); - $bundleCmd->run(); + $bundleCmd->execute(); diff --git a/docs/commands/clone.rst b/docs/commands/clone.rst index 427b840..c55558e 100644 --- a/docs/commands/clone.rst +++ b/docs/commands/clone.rst @@ -12,4 +12,4 @@ Examples: $cloneCmd = Factory::createClone(); $cloneCmd->setSource('/path/to/source'); - $cloneCmd->run(); + $cloneCmd->execute(); diff --git a/docs/commands/heads.rst b/docs/commands/heads.rst index 0eaee8f..a99dfbc 100644 --- a/docs/commands/heads.rst +++ b/docs/commands/heads.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $headsCmd = Factory::createHeads(); - $headsCmd->run(); + $headsCmd->execute(); diff --git a/docs/commands/init.rst b/docs/commands/init.rst index e671b4b..2714367 100644 --- a/docs/commands/init.rst +++ b/docs/commands/init.rst @@ -12,4 +12,4 @@ Examples: $initCmd = Factory::createInit(); $initCmd->setDestination('/path/to/destination'); - $initCmd->run(); + $initCmd->execute(); diff --git a/docs/commands/paths.rst b/docs/commands/paths.rst index e7a8ebd..e7027f4 100644 --- a/docs/commands/paths.rst +++ b/docs/commands/paths.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $pathsCmd = Factory::createPaths(); - $pathsCmd->run(); + $pathsCmd->execute(); diff --git a/docs/commands/root.rst b/docs/commands/root.rst index 13fce7f..edf9a09 100644 --- a/docs/commands/root.rst +++ b/docs/commands/root.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $rootCmd = Factory::createRoot(); - $rootCmd->run(); + $rootCmd->execute(); diff --git a/docs/commands/summary.rst b/docs/commands/summary.rst index 84e709f..e126af8 100644 --- a/docs/commands/summary.rst +++ b/docs/commands/summary.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $summaryCmd = Factory::createSummary(); - $summaryCmd->run(); + $summaryCmd->execute(); diff --git a/docs/commands/unbundle.rst b/docs/commands/unbundle.rst index 207ddc7..38fb4ea 100644 --- a/docs/commands/unbundle.rst +++ b/docs/commands/unbundle.rst @@ -14,4 +14,4 @@ Examples: $unbundleCmd->addFile('C:\\xampp\\file1\\'); $unbundleCmd->addFile('C:\\xampp\\file2\\'); $unbundleCmd->setUpdate(true); - $unbundleCmd->run(); + $unbundleCmd->execute(); diff --git a/docs/commands/verify.rst b/docs/commands/verify.rst index dccb28c..ae872fd 100644 --- a/docs/commands/verify.rst +++ b/docs/commands/verify.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $verifyCmd = Factory::createVerify(); - $verifyCmd->run(); + $verifyCmd->execute(); diff --git a/docs/commands/version.rst b/docs/commands/version.rst index 3ea35f6..5e4d178 100644 --- a/docs/commands/version.rst +++ b/docs/commands/version.rst @@ -11,4 +11,4 @@ Examples: use Siad007\VersionControl\HG\Factory; $versionCmd = Factory::createVersion(); - $versionCmd->run(); + $versionCmd->execute(); diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 2c3558c..3f87962 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -89,7 +89,10 @@ abstract class AbstractCommand * * @return string */ - abstract public function __toString(); + public function __toString() + { + return sprintf($this->command, $this); + } /** * Standard constructor. @@ -116,25 +119,26 @@ public function __construct($options = array()) * * @return string */ - public function run($return = false) + public function execute() { - if ($return) { - return sprintf($this->command, $this); - } else { - $output = array(); - $code = 0; - - exec(sprintf($this->command, $this) . " 2>&1", $output, $code); - - if ($code != 0) { - throw new \RuntimeException( - 'An error occurred while using Mercurial; hg returned: ' - . implode(PHP_EOL, $output) - ); - } else { - echo implode(PHP_EOL, $output); - } + $output = array(); + $code = 0; + + exec(sprintf($this->command, $this) . " 2>&1", $output, $code); + + if ($code != 0) { + throw new \RuntimeException( + 'An error occurred while using VersionControl_HG; hg returned: ' + . implode(PHP_EOL, $output), $code + ); } + + return implode(PHP_EOL, $output); + } + + public function asString() + { + return self::__toString(); } /** diff --git a/tests/Command/AddCommandTest.php b/tests/Command/AddCommandTest.php index 5eee04d..0eea003 100644 --- a/tests/Command/AddCommandTest.php +++ b/tests/Command/AddCommandTest.php @@ -36,6 +36,6 @@ public function addCommand() } $this->assertSame($file, implode(' ', $addCmd->getFile())); - $this->assertSame($expected . $file, $addCmd->run(true)); + $this->assertSame($expected . $file, $addCmd->asString()); } } diff --git a/tests/Command/AddremoveCommandTest.php b/tests/Command/AddremoveCommandTest.php index aae82b3..0b72b50 100644 --- a/tests/Command/AddremoveCommandTest.php +++ b/tests/Command/AddremoveCommandTest.php @@ -37,6 +37,6 @@ public function addremoveCommand() } $this->assertSame($file, implode(' ', $addremoveCmd->getFile())); - $this->assertSame($expected . $file, $addremoveCmd->run(true)); + $this->assertSame($expected . $file, $addremoveCmd->asString()); } } diff --git a/tests/Command/AnnotateCommandTest.php b/tests/Command/AnnotateCommandTest.php index d19597d..fa4cff3 100644 --- a/tests/Command/AnnotateCommandTest.php +++ b/tests/Command/AnnotateCommandTest.php @@ -34,6 +34,6 @@ public function annotateCommand() } $this->assertSame($file, implode(' ', $annotateCmd->getFile())); - $this->assertSame($expected . $file, $annotateCmd->run(true)); + $this->assertSame($expected . $file, $annotateCmd->asString()); } } diff --git a/tests/Command/ArchiveCommandTest.php b/tests/Command/ArchiveCommandTest.php index 8b623c5..cc64349 100644 --- a/tests/Command/ArchiveCommandTest.php +++ b/tests/Command/ArchiveCommandTest.php @@ -36,6 +36,6 @@ public function archiveCommand() } $this->assertSame($destination, $archiveCmd->getDestination()); - $this->assertSame($expected . $destination, $archiveCmd->run(true)); + $this->assertSame($expected . $destination, $archiveCmd->asString()); } } diff --git a/tests/Command/BundleCommandTest.php b/tests/Command/BundleCommandTest.php index c3598ff..8d38473 100644 --- a/tests/Command/BundleCommandTest.php +++ b/tests/Command/BundleCommandTest.php @@ -36,6 +36,6 @@ public function bundleCommand() } $this->assertSame($destination, $bundleCmd->getFile()); - $this->assertSame($expected . $destination, $bundleCmd->run(true)); + $this->assertSame($expected . $destination, $bundleCmd->asString()); } } diff --git a/tests/Command/CatCommandTest.php b/tests/Command/CatCommandTest.php index 132fabc..eb73da5 100644 --- a/tests/Command/CatCommandTest.php +++ b/tests/Command/CatCommandTest.php @@ -38,6 +38,6 @@ public function catCommand() } $this->assertSame($file, implode(' ', $catCmd->getFile())); - $this->assertSame($expected . $file, $catCmd->run(true)); + $this->assertSame($expected . $file, $catCmd->asString()); } } diff --git a/tests/Command/CloneCommandTest.php b/tests/Command/CloneCommandTest.php index 3f1eb1b..eb87cf0 100644 --- a/tests/Command/CloneCommandTest.php +++ b/tests/Command/CloneCommandTest.php @@ -57,7 +57,7 @@ public function cloneCommand() $expected = str_replace("'", '"', $expected); } - $this->assertSame($expected, $cloneCmd->run(true)); + $this->assertSame($expected, $cloneCmd->asString()); } /** @@ -76,7 +76,7 @@ public function cloneCommandWithoutDestination() $expected = str_replace("'", '"', $expected); } - $this->assertSame($expected, $cloneCmd->run(true)); + $this->assertSame($expected, $cloneCmd->asString()); } /** @@ -88,7 +88,7 @@ public function cloneCommandWithoutSource() $cloneCmd = Factory::getInstance('clone'); $cloneCmd->setUncompressed(true); $cloneCmd->setInsecure(true); - $cloneCmd->run(true); + $cloneCmd->asString(); $this->assertError("No source directory given.", E_USER_ERROR); } diff --git a/tests/Command/CommitCommandTest.php b/tests/Command/CommitCommandTest.php index 7e3227c..20cec42 100644 --- a/tests/Command/CommitCommandTest.php +++ b/tests/Command/CommitCommandTest.php @@ -45,6 +45,6 @@ public function commitCommand() } $this->assertSame($file, implode(' ', $commitCmd->getFile())); - $this->assertSame($expected . $file, $commitCmd->run(true)); + $this->assertSame($expected . $file, $commitCmd->asString()); } } diff --git a/tests/Command/HeadsCommandTest.php b/tests/Command/HeadsCommandTest.php index dd53435..49bf374 100644 --- a/tests/Command/HeadsCommandTest.php +++ b/tests/Command/HeadsCommandTest.php @@ -29,6 +29,6 @@ public function headsCommand() $expected = 'hg heads --rev startrev --topo --closed --template template'; - $this->assertSame($expected, $headsCmd->run(true)); + $this->assertSame($expected, $headsCmd->asString()); } } diff --git a/tests/Command/InitCommandTest.php b/tests/Command/InitCommandTest.php index 8a6916e..50e004d 100644 --- a/tests/Command/InitCommandTest.php +++ b/tests/Command/InitCommandTest.php @@ -36,6 +36,6 @@ public function initCommand() } $this->assertSame($destination, $initCmd->getDestination()); - $this->assertSame($expected . $destination, $initCmd->run(true)); + $this->assertSame($expected . $destination, $initCmd->asString()); } } diff --git a/tests/Command/ManifestCommandTest.php b/tests/Command/ManifestCommandTest.php index 16db50a..541e501 100644 --- a/tests/Command/ManifestCommandTest.php +++ b/tests/Command/ManifestCommandTest.php @@ -27,6 +27,6 @@ public function manifestCommand() $expected = 'hg manifest --rev test --all'; - $this->assertSame($expected, $manifestCmd->run(true)); + $this->assertSame($expected, $manifestCmd->asString()); } } diff --git a/tests/Command/PathsCommandTest.php b/tests/Command/PathsCommandTest.php index eeae486..05969c0 100644 --- a/tests/Command/PathsCommandTest.php +++ b/tests/Command/PathsCommandTest.php @@ -28,6 +28,6 @@ public function pathsCommand() $expected = 'hg paths test'; $this->assertSame('test', $pathsCmd->getName()); - $this->assertSame($expected, $pathsCmd->run(true)); + $this->assertSame($expected, $pathsCmd->asString()); } } diff --git a/tests/Command/PullCommandTest.php b/tests/Command/PullCommandTest.php index 57b85a0..723d487 100644 --- a/tests/Command/PullCommandTest.php +++ b/tests/Command/PullCommandTest.php @@ -41,6 +41,6 @@ public function pullCommand() } $this->assertSame($source, $pullCmd->getSource()); - $this->assertSame($expected . $source, $pullCmd->run(true)); + $this->assertSame($expected . $source, $pullCmd->asString()); } } diff --git a/tests/Command/PushCommandTest.php b/tests/Command/PushCommandTest.php index be23b49..d20673b 100644 --- a/tests/Command/PushCommandTest.php +++ b/tests/Command/PushCommandTest.php @@ -37,6 +37,6 @@ public function pushCommand() } $this->assertSame($destination, $pushCmd->getDestination()); - $this->assertSame($expected . $destination, $pushCmd->run(true)); + $this->assertSame($expected . $destination, $pushCmd->asString()); } } diff --git a/tests/Command/RootCommandTest.php b/tests/Command/RootCommandTest.php index f0fe8c1..95e96f5 100644 --- a/tests/Command/RootCommandTest.php +++ b/tests/Command/RootCommandTest.php @@ -26,6 +26,6 @@ public function rootCommand() $expected = 'hg root'; - $this->assertSame($expected, $rootCmd->run(true)); + $this->assertSame($expected, $rootCmd->asString()); } } diff --git a/tests/Command/SummaryCommandTest.php b/tests/Command/SummaryCommandTest.php index 89d71f0..49ef709 100644 --- a/tests/Command/SummaryCommandTest.php +++ b/tests/Command/SummaryCommandTest.php @@ -26,6 +26,6 @@ public function summaryCommand() $expected = 'hg summary --remote'; - $this->assertSame($expected, $summaryCmd->run(true)); + $this->assertSame($expected, $summaryCmd->asString()); } } diff --git a/tests/Command/TagCommandTest.php b/tests/Command/TagCommandTest.php index 6b8b7de..d3236cf 100644 --- a/tests/Command/TagCommandTest.php +++ b/tests/Command/TagCommandTest.php @@ -37,6 +37,6 @@ public function tagCommand() $expected = 'hg tag --force --local --rev test --remove --edit --message text --date date --user user '; $this->assertSame($name, implode(' ', $tagCmd->getName())); - $this->assertSame($expected . $name, $tagCmd->run(true)); + $this->assertSame($expected . $name, $tagCmd->asString()); } } diff --git a/tests/Command/UnbundleCommandTest.php b/tests/Command/UnbundleCommandTest.php index 7d60eec..117d8e2 100644 --- a/tests/Command/UnbundleCommandTest.php +++ b/tests/Command/UnbundleCommandTest.php @@ -34,6 +34,6 @@ public function unbundleCommand() } $this->assertSame($file, implode(' ', $unbundleCmd->getFile())); - $this->assertSame($expected . $file, $unbundleCmd->run(true)); + $this->assertSame($expected . $file, $unbundleCmd->asString()); } } diff --git a/tests/Command/UpdateCommandTest.php b/tests/Command/UpdateCommandTest.php index 365b314..0571fb8 100644 --- a/tests/Command/UpdateCommandTest.php +++ b/tests/Command/UpdateCommandTest.php @@ -29,6 +29,6 @@ public function updateCommand() $expected = 'hg update --clean --check --date date --rev rev'; - $this->assertSame($expected, $updateCmd->run(true)); + $this->assertSame($expected, $updateCmd->asString()); } } diff --git a/tests/Command/VerifyCommandTest.php b/tests/Command/VerifyCommandTest.php index 1398b69..55a1e01 100644 --- a/tests/Command/VerifyCommandTest.php +++ b/tests/Command/VerifyCommandTest.php @@ -25,6 +25,6 @@ public function verifyCommand() $expected = 'hg verify'; - $this->assertSame($expected, $verifyCmd->run(true)); + $this->assertSame($expected, $verifyCmd->asString()); } }