1
0
Fork 0

Update callers of VersionParser::formatVersion()

Tests were moved to BasePackageTest.
pull/4086/head
Kunal Mehta 2015-05-30 23:30:52 -07:00
parent 99dab8aebd
commit f634c6946d
8 changed files with 62 additions and 65 deletions

View File

@ -298,7 +298,7 @@ EOT
}); });
} }
$io->writeError('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>'); $io->writeError('<info>Installing ' . $package->getName() . ' (' . $package->getFullPrettyVersion(false) . ')</info>');
if ($disablePlugins) { if ($disablePlugins) {
$io->writeError('<info>Plugins have been disabled.</info>'); $io->writeError('<info>Plugins have been disabled.</info>');

View File

@ -13,7 +13,6 @@
namespace Composer\Command; namespace Composer\Command;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\Version\VersionParser;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
@ -56,8 +55,6 @@ EOT
$root = $composer->getPackage(); $root = $composer->getPackage();
$repo = $composer->getRepositoryManager()->getLocalRepository(); $repo = $composer->getRepositoryManager()->getLocalRepository();
$versionParser = new VersionParser;
if ($input->getOption('no-dev')) { if ($input->getOption('no-dev')) {
$packages = $this->filterRequiredPackages($repo, $root); $packages = $this->filterRequiredPackages($repo, $root);
} else { } else {
@ -69,7 +66,7 @@ EOT
switch ($format = $input->getOption('format')) { switch ($format = $input->getOption('format')) {
case 'text': case 'text':
$this->getIO()->write('Name: <comment>'.$root->getPrettyName().'</comment>'); $this->getIO()->write('Name: <comment>'.$root->getPrettyName().'</comment>');
$this->getIO()->write('Version: <comment>'.$versionParser->formatVersion($root).'</comment>'); $this->getIO()->write('Version: <comment>'.$root->getFullPrettyVersion().'</comment>');
$this->getIO()->write('Licenses: <comment>'.(implode(', ', $root->getLicense()) ?: 'none').'</comment>'); $this->getIO()->write('Licenses: <comment>'.(implode(', ', $root->getLicense()) ?: 'none').'</comment>');
$this->getIO()->write('Dependencies:'); $this->getIO()->write('Dependencies:');
$this->getIO()->write(''); $this->getIO()->write('');
@ -82,7 +79,7 @@ EOT
foreach ($packages as $package) { foreach ($packages as $package) {
$table->addRow(array( $table->addRow(array(
$package->getPrettyName(), $package->getPrettyName(),
$versionParser->formatVersion($package), $package->getFullPrettyVersion(),
implode(', ', $package->getLicense()) ?: 'none', implode(', ', $package->getLicense()) ?: 'none',
)); ));
} }
@ -92,14 +89,14 @@ EOT
case 'json': case 'json':
foreach ($packages as $package) { foreach ($packages as $package) {
$dependencies[$package->getPrettyName()] = array( $dependencies[$package->getPrettyName()] = array(
'version' => $versionParser->formatVersion($package), 'version' => $package->getFullPrettyVersion(),
'license' => $package->getLicense(), 'license' => $package->getLicense(),
); );
} }
$this->getIO()->write(JsonFile::encode(array( $this->getIO()->write(JsonFile::encode(array(
'name' => $root->getPrettyName(), 'name' => $root->getPrettyName(),
'version' => $versionParser->formatVersion($root), 'version' => $root->getFullPrettyVersion(),
'license' => $root->getLicense(), 'license' => $root->getLicense(),
'dependencies' => $dependencies, 'dependencies' => $dependencies,
))); )));

View File

@ -181,7 +181,7 @@ EOT
foreach ($packages[$type] as $package) { foreach ($packages[$type] as $package) {
if (is_object($package)) { if (is_object($package)) {
$nameLength = max($nameLength, strlen($package->getPrettyName())); $nameLength = max($nameLength, strlen($package->getPrettyName()));
$versionLength = max($versionLength, strlen($this->versionParser->formatVersion($package))); $versionLength = max($versionLength, strlen($package->getFullPrettyVersion()));
} else { } else {
$nameLength = max($nameLength, $package); $nameLength = max($nameLength, $package);
} }
@ -209,7 +209,7 @@ EOT
$output->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false); $output->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false);
if ($writeVersion) { if ($writeVersion) {
$output->write(' ' . str_pad($this->versionParser->formatVersion($package), $versionLength, ' '), false); $output->write(' ' . str_pad($package->getFullPrettyVersion(), $versionLength, ' '), false);
} }
if ($writeDescription) { if ($writeDescription) {

View File

@ -12,7 +12,6 @@
namespace Composer\DependencyResolver\Operation; namespace Composer\DependencyResolver\Operation;
use Composer\Package\Version\VersionParser;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
/** /**
@ -46,6 +45,6 @@ abstract class SolverOperation implements OperationInterface
protected function formatVersion(PackageInterface $package) protected function formatVersion(PackageInterface $package)
{ {
return VersionParser::formatVersion($package); return $package->getFullPrettyVersion();
} }
} }

View File

@ -16,7 +16,6 @@ use Composer\Config;
use Composer\Cache; use Composer\Cache;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\Version\VersionParser;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Plugin\PreFileDownloadEvent; use Composer\Plugin\PreFileDownloadEvent;
use Composer\EventDispatcher\EventDispatcher; use Composer\EventDispatcher\EventDispatcher;
@ -81,7 +80,7 @@ class FileDownloader implements DownloaderInterface
throw new \InvalidArgumentException('The given package is missing url information'); throw new \InvalidArgumentException('The given package is missing url information');
} }
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)"); $this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
$urls = $package->getDistUrls(); $urls = $package->getDistUrls();
while ($url = array_shift($urls)) { while ($url = array_shift($urls)) {
@ -205,7 +204,7 @@ class FileDownloader implements DownloaderInterface
*/ */
public function remove(PackageInterface $package, $path) public function remove(PackageInterface $package, $path)
{ {
$this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)"); $this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
if (!$this->filesystem->removeDirectory($path)) { if (!$this->filesystem->removeDirectory($path)) {
throw new \RuntimeException('Could not completely delete '.$path.', aborting.'); throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
} }

View File

@ -14,7 +14,6 @@ namespace Composer\Downloader;
use Composer\Config; use Composer\Config;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\Version\VersionParser;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
@ -54,7 +53,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information'); throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
} }
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)"); $this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
$this->filesystem->emptyDirectory($path); $this->filesystem->emptyDirectory($path);
$urls = $package->getSourceUrls(); $urls = $package->getSourceUrls();
@ -100,8 +99,8 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
} }
$name .= ' '.$initial->getPrettyVersion(); $name .= ' '.$initial->getPrettyVersion();
} else { } else {
$from = VersionParser::formatVersion($initial); $from = $initial->getFullPrettyVersion();
$to = VersionParser::formatVersion($target); $to = $target->getFullPrettyVersion();
} }
$this->io->writeError(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)"); $this->io->writeError(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");

View File

@ -12,6 +12,8 @@
namespace Composer\Test\Package; namespace Composer\Test\Package;
use Composer\Package\BasePackage;
class BasePackageTest extends \PHPUnit_Framework_TestCase class BasePackageTest extends \PHPUnit_Framework_TestCase
{ {
public function testSetSameRepository() public function testSetSameRepository()
@ -37,4 +39,51 @@ class BasePackageTest extends \PHPUnit_Framework_TestCase
$package->setRepository($this->getMock('Composer\Repository\RepositoryInterface')); $package->setRepository($this->getMock('Composer\Repository\RepositoryInterface'));
$package->setRepository($this->getMock('Composer\Repository\RepositoryInterface')); $package->setRepository($this->getMock('Composer\Repository\RepositoryInterface'));
} }
/**
* @dataProvider formattedVersions
*/
public function testFormatVersionForDevPackage(BasePackage $package, $truncate, $expected)
{
$this->assertSame($expected, $package->getFullPrettyVersion($truncate));
}
public function formattedVersions()
{
$data = array(
array(
'sourceReference' => 'v2.1.0-RC2',
'truncate' => true,
'expected' => 'PrettyVersion v2.1.0-RC2'
),
array(
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
'truncate' => true,
'expected' => 'PrettyVersion bbf527a'
),
array(
'sourceReference' => 'v1.0.0',
'truncate' => false,
'expected' => 'PrettyVersion v1.0.0'
),
array(
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
'truncate' => false,
'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77'
),
);
$self = $this;
$createPackage = function ($arr) use ($self) {
$package = $self->getMockForAbstractClass('\Composer\Package\BasePackage', array(), '', false);
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
$package->expects($self->any())->method('getSourceReference')->will($self->returnValue($arr['sourceReference']));
return array($package, $arr['truncate'], $arr['expected']);
};
return array_map($createPackage, $data);
}
} }

View File

@ -21,52 +21,6 @@ use Composer\Package\PackageInterface;
class VersionParserTest extends \PHPUnit_Framework_TestCase class VersionParserTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @dataProvider formattedVersions
*/
public function testFormatVersionForDevPackage(PackageInterface $package, $truncate, $expected)
{
$this->assertSame($expected, VersionParser::formatVersion($package, $truncate));
}
public function formattedVersions()
{
$data = array(
array(
'sourceReference' => 'v2.1.0-RC2',
'truncate' => true,
'expected' => 'PrettyVersion v2.1.0-RC2'
),
array(
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
'truncate' => true,
'expected' => 'PrettyVersion bbf527a'
),
array(
'sourceReference' => 'v1.0.0',
'truncate' => false,
'expected' => 'PrettyVersion v1.0.0'
),
array(
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
'truncate' => false,
'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77'
),
);
$self = $this;
$createPackage = function ($arr) use ($self) {
$package = $self->getMockForAbstractClass('\Composer\Package\BasePackage', array(), '', false);
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
$package->expects($self->any())->method('getSourceReference')->will($self->returnValue($arr['sourceReference']));
return array($package, $arr['truncate'], $arr['expected']);
};
return array_map($createPackage, $data);
}
/** /**
* @dataProvider numericAliasVersions * @dataProvider numericAliasVersions