Skip to content

Commit

Permalink
Changed execution
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 committed Aug 30, 2014
1 parent fbfe57c commit aa70dfc
Show file tree
Hide file tree
Showing 34 changed files with 57 additions and 53 deletions.
2 changes: 1 addition & 1 deletion docs/commands/add.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$addCmd = Factory::createAdd();
$addCmd->run();
$addCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/addremove.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$addremoveCmd = Factory::createAddremove();
$addremoveCmd->run();
$addremoveCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/archive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Examples:
$archiveCmd->addExclude('excludePattern');
$archiveCmd->setSubrepos(tru);
$archiveCmd->setNoDecode(true);
$archiveCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/bundle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Examples:
$bundleCmd->setInsecure(true);
$bundleCmd->setVerbose(true);
$bundleCmd->setEncoding('UTF-8');
$bundleCmd->run();
$bundleCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/clone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Examples:
$cloneCmd = Factory::createClone();
$cloneCmd->setSource('/path/to/source');
$cloneCmd->run();
$cloneCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/heads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$headsCmd = Factory::createHeads();
$headsCmd->run();
$headsCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Examples:
$initCmd = Factory::createInit();
$initCmd->setDestination('/path/to/destination');
$initCmd->run();
$initCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/paths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$pathsCmd = Factory::createPaths();
$pathsCmd->run();
$pathsCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/root.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$rootCmd = Factory::createRoot();
$rootCmd->run();
$rootCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$summaryCmd = Factory::createSummary();
$summaryCmd->run();
$summaryCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/unbundle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Examples:
$unbundleCmd->addFile('C:\\xampp\\file1\\');
$unbundleCmd->addFile('C:\\xampp\\file2\\');
$unbundleCmd->setUpdate(true);
$unbundleCmd->run();
$unbundleCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/verify.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$verifyCmd = Factory::createVerify();
$verifyCmd->run();
$verifyCmd->execute();
2 changes: 1 addition & 1 deletion docs/commands/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Examples:
use Siad007\VersionControl\HG\Factory;
$versionCmd = Factory::createVersion();
$versionCmd->run();
$versionCmd->execute();
40 changes: 22 additions & 18 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ abstract class AbstractCommand
*
* @return string
*/
abstract public function __toString();
public function __toString()
{
return sprintf($this->command, $this);
}

/**
* Standard constructor.
Expand All @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/AddCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/AddremoveCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/AnnotateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/ArchiveCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/BundleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/CatCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 3 additions & 3 deletions tests/Command/CloneCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function cloneCommand()
$expected = str_replace("'", '"', $expected);
}

$this->assertSame($expected, $cloneCmd->run(true));
$this->assertSame($expected, $cloneCmd->asString());
}

/**
Expand All @@ -76,7 +76,7 @@ public function cloneCommandWithoutDestination()
$expected = str_replace("'", '"', $expected);
}

$this->assertSame($expected, $cloneCmd->run(true));
$this->assertSame($expected, $cloneCmd->asString());
}

/**
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/CommitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/HeadsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/ManifestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function manifestCommand()

$expected = 'hg manifest --rev test --all';

$this->assertSame($expected, $manifestCmd->run(true));
$this->assertSame($expected, $manifestCmd->asString());
}
}
2 changes: 1 addition & 1 deletion tests/Command/PathsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/PullCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/PushCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/RootCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public function rootCommand()

$expected = 'hg root';

$this->assertSame($expected, $rootCmd->run(true));
$this->assertSame($expected, $rootCmd->asString());
}
}
2 changes: 1 addition & 1 deletion tests/Command/SummaryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public function summaryCommand()

$expected = 'hg summary --remote';

$this->assertSame($expected, $summaryCmd->run(true));
$this->assertSame($expected, $summaryCmd->asString());
}
}
2 changes: 1 addition & 1 deletion tests/Command/TagCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/UnbundleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/UpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Command/VerifyCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function verifyCommand()

$expected = 'hg verify';

$this->assertSame($expected, $verifyCmd->run(true));
$this->assertSame($expected, $verifyCmd->asString());
}
}

0 comments on commit aa70dfc

Please sign in to comment.