1
0
Fork 0

Add prettyVersion to packages, fixes #76

pull/119/head
Jordi Boggiano 2011-11-20 15:06:12 +01:00
parent 4140f08d9c
commit 8e6f8ae57e
16 changed files with 178 additions and 146 deletions

View File

@ -44,8 +44,9 @@ class ArrayLoader
public function load($config)
{
$version = $this->versionParser->normalize(isset($config['version']) ? $config['version'] : '0.0.0');
$package = new Package\MemoryPackage(isset($config['name']) ? $config['name'] : '__app__', $version);
$prettyVersion = isset($config['version']) ? $config['version'] : '0.0.0';
$version = $this->versionParser->normalize($prettyVersion);
$package = new Package\MemoryPackage(isset($config['name']) ? $config['name'] : '__app__', $version, $prettyVersion);
$package->setType(isset($config['type']) ? $config['type'] : 'library');

View File

@ -29,8 +29,8 @@ class MemoryPackage extends BasePackage
protected $distUrl;
protected $distReference;
protected $distSha1Checksum;
protected $releaseType;
protected $version;
protected $prettyVersion;
protected $repositories;
protected $license;
protected $extra = array();
@ -48,14 +48,14 @@ class MemoryPackage extends BasePackage
*
* @param string $name The package's name
* @param string $version The package's version
* @param string $releaseType The package's release type (beta/rc/stable/dev)
* @param string $prettyVersion The package's non-normalized version
*/
public function __construct($name, $version, $releaseType = 'stable')
public function __construct($name, $version, $prettyVersion)
{
parent::__construct($name);
$this->releaseType = $releaseType;
$this->version = $version;
$this->prettyVersion = $prettyVersion;
}
/**
@ -252,34 +252,6 @@ class MemoryPackage extends BasePackage
return $this->repositories;
}
/**
* Set the release type
*
* @param string $releaseType
*/
public function setReleaseType($releaseType)
{
$this->releaseType = $releaseType;
}
/**
* {@inheritDoc}
*/
public function getReleaseType()
{
return $this->releaseType;
}
/**
* Set the version
*
* @param string $version
*/
public function setVersion($version)
{
$this->version = $version;
}
/**
* {@inheritDoc}
*/
@ -288,6 +260,14 @@ class MemoryPackage extends BasePackage
return $this->version;
}
/**
* {@inheritDoc}
*/
public function getPrettyVersion()
{
return $this->prettyVersion;
}
/**
* Set the license
*

View File

@ -159,6 +159,13 @@ interface PackageInterface
*/
function getVersion();
/**
* Returns the pretty (i.e. non-normalized) version string of this package
*
* @return string version
*/
function getPrettyVersion();
/**
* Returns the package license, e.g. MIT, BSD, GPL
*

View File

@ -12,10 +12,6 @@
namespace Composer\Repository;
use Composer\Package\MemoryPackage;
use Composer\Package\BasePackage;
use Composer\Package\Link;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Package\Loader\ArrayLoader;
/**

View File

@ -13,8 +13,6 @@
namespace Composer\Repository;
use Composer\Package\MemoryPackage;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Package\Version\VersionParser;
/**
@ -36,12 +34,14 @@ class PlatformRepository extends ArrayRepository
$versionParser = new VersionParser();
try {
$version = $versionParser->normalize(PHP_VERSION);
$prettyVersion = PHP_VERSION;
$version = $versionParser->normalize($prettyVersion);
} catch (\UnexpectedValueException $e) {
$version = $versionParser->normalize(preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION));
$prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
$version = $versionParser->normalize($prettyVersion);
}
$php = new MemoryPackage('php', $version);
$php = new MemoryPackage('php', $version, $prettyVersion);
parent::addPackage($php);
foreach (get_loaded_extensions() as $ext) {
@ -51,12 +51,14 @@ class PlatformRepository extends ArrayRepository
$reflExt = new \ReflectionExtension($ext);
try {
$version = $versionParser->normalize($reflExt->getVersion());
$prettyVersion = $reflExt->getVersion();
$version = $versionParser->normalize($prettyVersion);
} catch (\UnexpectedValueException $e) {
$version = $versionParser->normalize('0');
$prettyVersion = '0';
$version = $versionParser->normalize($prettyVersion);
}
$ext = new MemoryPackage('ext-'.strtolower($ext), $version);
$ext = new MemoryPackage('ext-'.strtolower($ext), $version, $prettyVersion);
parent::addPackage($ext);
}
}

View File

@ -17,11 +17,11 @@ use Composer\Repository\RepositoryInterface;
use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Literal;
use Composer\Package\MemoryPackage;
use Composer\Package\Link;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Test\TestCase;
class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
class DefaultPolicyTest extends TestCase
{
protected $pool;
protected $repo;
@ -40,7 +40,7 @@ class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
public function testSelectSingle()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repo);
$literals = array(new Literal($packageA, true));
@ -53,8 +53,8 @@ class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
public function testSelectNewest()
{
$this->repo->addPackage($packageA1 = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA2 = new MemoryPackage('A', '2.0'));
$this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0'));
$this->pool->addRepository($this->repo);
$literals = array(new Literal($packageA1, true), new Literal($packageA2, true));
@ -67,8 +67,8 @@ class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
public function testSelectNewestOverInstalled()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '2.0'));
$this->repoInstalled->addPackage($packageAInstalled = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
$this->repoInstalled->addPackage($packageAInstalled = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repoInstalled);
$this->pool->addRepository($this->repo);
@ -84,8 +84,8 @@ class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
{
$this->repoImportant = new ArrayRepository;
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repoImportant->addPackage($packageAImportant = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repoInstalled);
$this->pool->addRepository($this->repo);
@ -101,8 +101,8 @@ class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
public function testSelectAllProviders()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '2.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '2.0'));
$packageA->setProvides(array(new Link('A', 'X', new VersionConstraint('==', '1.0'), 'provides')));
$packageB->setProvides(array(new Link('B', 'X', new VersionConstraint('==', '1.0'), 'provides')));
@ -120,8 +120,8 @@ class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
public function testPreferNonReplacingFromSameRepo()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '2.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '2.0'));
$packageB->setReplaces(array(new Link('B', 'A', new VersionConstraint('==', '1.0'), 'replaces')));

View File

@ -13,15 +13,15 @@
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\Literal;
use Composer\Package\MemoryPackage;
use Composer\Test\TestCase;
class LiteralTest extends \PHPUnit_Framework_TestCase
class LiteralTest extends TestCase
{
protected $package;
public function setUp()
{
$this->package = new MemoryPackage('foo', '1');
$this->package = $this->getPackage('foo', '1');
$this->package->setId(12);
}

View File

@ -14,15 +14,15 @@ namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\Pool;
use Composer\Repository\ArrayRepository;
use Composer\Package\MemoryPackage;
use Composer\Test\TestCase;
class PoolTest extends \PHPUnit_Framework_TestCase
class PoolTest extends TestCase
{
public function testPool()
{
$pool = new Pool;
$repo = new ArrayRepository;
$package = new MemoryPackage('foo', '1');
$package = $this->getPackage('foo', '1');
$repo->addPackage($package);
$pool->addRepository($repo);

View File

@ -16,17 +16,17 @@ use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Pool;
use Composer\Repository\ArrayRepository;
use Composer\DependencyResolver\Literal;
use Composer\Package\MemoryPackage;
use Composer\Test\TestCase;
class RequestTest extends \PHPUnit_Framework_TestCase
class RequestTest extends TestCase
{
public function testRequestInstallAndRemove()
{
$pool = new Pool;
$repo = new ArrayRepository;
$foo = new MemoryPackage('foo', '1');
$bar = new MemoryPackage('bar', '1');
$foobar = new MemoryPackage('foobar', '1');
$foo = $this->getPackage('foo', '1');
$bar = $this->getPackage('bar', '1');
$foobar = $this->getPackage('foobar', '1');
$repo->addPackage($foo);
$repo->addPackage($bar);

View File

@ -19,11 +19,11 @@ use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Solver;
use Composer\Package\MemoryPackage;
use Composer\Package\Link;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Test\TestCase;
class SolverTest extends \PHPUnit_Framework_TestCase
class SolverTest extends TestCase
{
protected $pool;
protected $repo;
@ -44,7 +44,7 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverInstallSingle()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->reposComplete();
$this->request->install('A');
@ -56,9 +56,9 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverInstallWithDeps()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = new MemoryPackage('B', '1.1'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires')));
@ -74,7 +74,7 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverInstallInstalled()
{
$this->repoInstalled->addPackage(new MemoryPackage('A', '1.0'));
$this->repoInstalled->addPackage($this->getPackage('A', '1.0'));
$this->reposComplete();
$this->request->install('A');
@ -84,8 +84,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverInstallInstalledWithAlternative()
{
$this->repo->addPackage(new MemoryPackage('A', '1.0'));
$this->repoInstalled->addPackage(new MemoryPackage('A', '1.0'));
$this->repo->addPackage($this->getPackage('A', '1.0'));
$this->repoInstalled->addPackage($this->getPackage('A', '1.0'));
$this->reposComplete();
$this->request->install('A');
@ -95,7 +95,7 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverRemoveSingle()
{
$this->repoInstalled->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->reposComplete();
$this->request->remove('A');
@ -107,7 +107,7 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverRemoveUninstalled()
{
$this->repo->addPackage(new MemoryPackage('A', '1.0'));
$this->repo->addPackage($this->getPackage('A', '1.0'));
$this->reposComplete();
$this->request->remove('A');
@ -117,8 +117,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverUpdateSingle()
{
$this->repoInstalled->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($newPackageA = new MemoryPackage('A', '1.1'));
$this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
$this->reposComplete();
$this->request->update('A');
@ -130,8 +130,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverUpdateCurrent()
{
$this->repoInstalled->addPackage(new MemoryPackage('A', '1.0'));
$this->repo->addPackage(new MemoryPackage('A', '1.0'));
$this->repoInstalled->addPackage($this->getPackage('A', '1.0'));
$this->repo->addPackage($this->getPackage('A', '1.0'));
$this->reposComplete();
$this->request->update('A');
@ -141,14 +141,14 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverAllJobs()
{
$this->repoInstalled->addPackage($packageD = new MemoryPackage('D', '1.0'));
$this->repoInstalled->addPackage($oldPackageC = new MemoryPackage('C', '1.0'));
$this->repoInstalled->addPackage($packageD = $this->getPackage('D', '1.0'));
$this->repoInstalled->addPackage($oldPackageC = $this->getPackage('C', '1.0'));
$this->repo->addPackage($packageA = new MemoryPackage('A', '2.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = new MemoryPackage('B', '1.1'));
$this->repo->addPackage($packageC = new MemoryPackage('C', '1.1'));
$this->repo->addPackage(new MemoryPackage('D', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$this->repo->addPackage($packageC = $this->getPackage('C', '1.1'));
$this->repo->addPackage($this->getPackage('D', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires')));
$this->reposComplete();
@ -167,10 +167,10 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverThreeAlternativeRequireAndConflict()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '2.0'));
$this->repo->addPackage($middlePackageB = new MemoryPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = new MemoryPackage('B', '1.1'));
$this->repo->addPackage($oldPackageB = new MemoryPackage('B', '0.9'));
$this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
$this->repo->addPackage($middlePackageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$this->repo->addPackage($oldPackageB = $this->getPackage('B', '0.9'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires')));
$packageA->setConflicts(array(new Link('A', 'B', new VersionConstraint('<', '1.0'), 'conflicts')));
@ -186,8 +186,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSolverObsolete()
{
$this->repoInstalled->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageB->setReplaces(array(new Link('B', 'A', null)));
$this->reposComplete();
@ -201,8 +201,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testInstallOneOfTwoAlternatives()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('A', '1.0'));
$this->reposComplete();
@ -215,9 +215,9 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testInstallProvider()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '0.8'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '0.8'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setProvides(array(new Link('Q', 'B', new VersionConstraint('=', '1.0'), 'provides')));
@ -233,9 +233,9 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSkipReplacerOfExistingPackage()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
@ -251,8 +251,8 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testInstallReplacerOfMissingPackage()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
@ -268,9 +268,9 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testSkipReplacedPackageIfReplacerIsSelected()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
@ -287,9 +287,9 @@ class SolverTest extends \PHPUnit_Framework_TestCase
public function testInstallCircularRequire()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB1 = new MemoryPackage('B', '0.9'));
$this->repo->addPackage($packageB2 = new MemoryPackage('B', '1.1'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB1 = $this->getPackage('B', '0.9'));
$this->repo->addPackage($packageB2 = $this->getPackage('B', '1.1'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
$packageB2->setRequires(array(new Link('B', 'A', new VersionConstraint('>=', '1.0'), 'requires')));
@ -307,10 +307,10 @@ class SolverTest extends \PHPUnit_Framework_TestCase
{
$this->markTestIncomplete();
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$this->repo->addPackage($packageC = new MemoryPackage('C', '1.0'));
$this->repo->addPackage($packageD = new MemoryPackage('D', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($packageC = $this->getPackage('C', '1.0'));
$this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
$packageB->setRequires(array(new Link('B', 'Virtual', new VersionConstraint('>=', '1.0'), 'requires')));
$packageC->setRequires(array(new Link('C', 'Virtual', new VersionConstraint('==', '1.0'), 'provides')));

View File

@ -189,7 +189,7 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
private function createPackageMock()
{
return $this->getMockBuilder('Composer\Package\MemoryPackage')
->setConstructorArgs(array(md5(rand()), '1.0.0'))
->setConstructorArgs(array(md5(rand()), '1.0.0.0', '1.0.0'))
->getMock();
}
}

View File

@ -13,10 +13,11 @@
namespace Composer\Test\Package;
use Composer\Package\MemoryPackage;
use Composer\Package\Version\VersionParser;
use Composer\Test\TestCase;
class MemoryPackageTest extends \PHPUnit_Framework_TestCase
class MemoryPackageTest extends TestCase
{
/**
* Memory package naming, versioning, and marshalling semantics provider
*
@ -24,11 +25,11 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase
*/
public function providerVersioningSchemes()
{
$provider[] = array('foo', '1-beta', 'foo-1-beta');
$provider[] = array('node', '0.5.6', 'node-0.5.6');
$provider[] = array('li3', '0.10', 'li3-0.10');
$provider[] = array('mongodb_odm', '1.0.0BETA3', 'mongodb_odm-1.0.0BETA3');
$provider[] = array('DoctrineCommon', '2.2.0-DEV', 'doctrinecommon-2.2.0-DEV');
$provider[] = array('foo', '1-beta');
$provider[] = array('node', '0.5.6');
$provider[] = array('li3', '0.10');
$provider[] = array('mongodb_odm', '1.0.0BETA3');
$provider[] = array('DoctrineCommon', '2.2.0-DEV');
return $provider;
}
@ -39,7 +40,9 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase
*/
public function testMemoryPackageHasExpectedNamingSemantics($name, $version)
{
$package = new MemoryPackage($name, $version);
$versionParser = new VersionParser();
$normVersion = $versionParser->normalize($version);
$package = new MemoryPackage($name, $normVersion, $version);
$this->assertEquals(strtolower($name), $package->getName());
}
@ -49,18 +52,23 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase
*/
public function testMemoryPackageHasExpectedVersioningSemantics($name, $version)
{
$package = new MemoryPackage($name, $version);
$this->assertEquals($version, $package->getVersion());
$versionParser = new VersionParser();
$normVersion = $versionParser->normalize($version);
$package = new MemoryPackage($name, $normVersion, $version);
$this->assertEquals($version, $package->getPrettyVersion());
$this->assertEquals($normVersion, $package->getVersion());
}
/**
* Tests memory package marshalling/serialization semantics
* @dataProvider providerVersioningSchemes
*/
public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version, $marshalled)
public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version)
{
$package = new MemoryPackage($name, $version);
$this->assertEquals($marshalled, (string) $package);
$versionParser = new VersionParser();
$normVersion = $versionParser->normalize($version);
$package = new MemoryPackage($name, $normVersion, $version);
$this->assertEquals(strtolower($name).'-'.$normVersion, (string) $package);
}
}

View File

@ -13,29 +13,29 @@
namespace Composer\Test\Repository;
use Composer\Repository\ArrayRepository;
use Composer\Package\MemoryPackage;
use Composer\Test\TestCase;
class ArrayRepositoryTest extends \PHPUnit_Framework_TestCase
class ArrayRepositoryTest extends TestCase
{
public function testAddPackage()
{
$repo = new ArrayRepository;
$repo->addPackage(new MemoryPackage('foo', '1'));
$repo->addPackage($this->getPackage('foo', '1'));
$this->assertEquals(1, count($repo));
}
public function testRemovePackage()
{
$package = new MemoryPackage('bar', '2');
$package = $this->getPackage('bar', '2');
$repo = new ArrayRepository;
$repo->addPackage(new MemoryPackage('foo', '1'));
$repo->addPackage($this->getPackage('foo', '1'));
$repo->addPackage($package);
$this->assertEquals(2, count($repo));
$repo->removePackage(new MemoryPackage('foo', '1'));
$repo->removePackage($this->getPackage('foo', '1'));
$this->assertEquals(1, count($repo));
$this->assertEquals(array($package), $repo->getPackages());
@ -44,10 +44,10 @@ class ArrayRepositoryTest extends \PHPUnit_Framework_TestCase
public function testHasPackage()
{
$repo = new ArrayRepository;
$repo->addPackage(new MemoryPackage('foo', '1'));
$repo->addPackage(new MemoryPackage('bar', '2'));
$repo->addPackage($this->getPackage('foo', '1'));
$repo->addPackage($this->getPackage('bar', '2'));
$this->assertTrue($repo->hasPackage(new MemoryPackage('foo', '1')));
$this->assertFalse($repo->hasPackage(new MemoryPackage('bar', '1')));
$this->assertTrue($repo->hasPackage($this->getPackage('foo', '1')));
$this->assertFalse($repo->hasPackage($this->getPackage('bar', '1')));
}
}

View File

@ -13,9 +13,9 @@
namespace Composer\Repository;
use Composer\Repository\FilesystemRepository;
use Composer\Package\MemoryPackage;
use Composer\Test\TestCase;
class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
class FilesystemRepositoryTest extends TestCase
{
public function testRepositoryRead()
{
@ -99,10 +99,10 @@ class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
->expects($this->once())
->method('write')
->with(array(
array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10')
array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10.0')
));
$repository->addPackage(new MemoryPackage('mypkg', '0.1.10'));
$repository->addPackage($this->getPackage('mypkg', '0.1.10'));
$repository->write();
}

View File

@ -0,0 +1,34 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test;
use Composer\Package\Version\VersionParser;
use Composer\Package\MemoryPackage;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
private static $versionParser;
public static function setUpBeforeClass()
{
if (!self::$versionParser) {
self::$versionParser = new VersionParser();
}
}
protected function getPackage($name, $version)
{
$normVersion = self::$versionParser->normalize($version);
return new MemoryPackage($name, $normVersion, $version);
}
}

View File

@ -11,3 +11,7 @@
*/
require __DIR__.'/../vendor/.composer/autoload.php';
$loader = new Composer\Autoload\ClassLoader();
$loader->add('Composer\Test', __DIR__);
$loader->register();