Add test for Pool handling and refactor a couple things
parent
0936670213
commit
453b9a616b
|
@ -33,10 +33,16 @@ class Pool
|
||||||
protected $acceptableStabilities;
|
protected $acceptableStabilities;
|
||||||
protected $stabilityFlags;
|
protected $stabilityFlags;
|
||||||
|
|
||||||
|
// TODO BC change to stable end of june?
|
||||||
public function __construct($minimumStability = 'dev', array $stabilityFlags = array())
|
public function __construct($minimumStability = 'dev', array $stabilityFlags = array())
|
||||||
{
|
{
|
||||||
$stabilities = BasePackage::$stabilities;
|
$stabilities = BasePackage::$stabilities;
|
||||||
$this->acceptableStabilities = array_flip(array_splice($stabilities, 0, array_search($minimumStability, $stabilities) + 1));
|
$this->acceptableStabilities = array();
|
||||||
|
foreach (BasePackage::$stabilities as $stability => $value) {
|
||||||
|
if ($value <= BasePackage::$stabilities[$minimumStability]) {
|
||||||
|
$this->acceptableStabilities[$stability] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->stabilityFlags = $stabilityFlags;
|
$this->stabilityFlags = $stabilityFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +75,7 @@ class Pool
|
||||||
&& isset($this->acceptableStabilities[$stability]))
|
&& isset($this->acceptableStabilities[$stability]))
|
||||||
// allow if package matches the package-specific stability flag
|
// allow if package matches the package-specific stability flag
|
||||||
|| (isset($this->stabilityFlags[$name])
|
|| (isset($this->stabilityFlags[$name])
|
||||||
&& array_search($stability, BasePackage::$stabilities) <= $this->stabilityFlags[$name]
|
&& BasePackage::$stabilities[$stability] <= $this->stabilityFlags[$name]
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
$package->setId($id++);
|
$package->setId($id++);
|
||||||
|
|
|
@ -32,12 +32,18 @@ abstract class BasePackage implements PackageInterface
|
||||||
'require-dev' => array('description' => 'requires (for development)', 'method' => 'devRequires'),
|
'require-dev' => array('description' => 'requires (for development)', 'method' => 'devRequires'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const STABILITY_STABLE = 0;
|
||||||
|
const STABILITY_RC = 5;
|
||||||
|
const STABILITY_BETA = 10;
|
||||||
|
const STABILITY_ALPHA = 15;
|
||||||
|
const STABILITY_DEV = 20;
|
||||||
|
|
||||||
public static $stabilities = array(
|
public static $stabilities = array(
|
||||||
'stable',
|
'stable' => self::STABILITY_STABLE,
|
||||||
'RC',
|
'RC' => self::STABILITY_RC,
|
||||||
'beta',
|
'beta' => self::STABILITY_BETA,
|
||||||
'alpha',
|
'alpha' => self::STABILITY_ALPHA,
|
||||||
'dev',
|
'dev' => self::STABILITY_DEV,
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
|
@ -120,9 +120,9 @@ class RootPackageLoader extends ArrayLoader
|
||||||
$stabilities = BasePackage::$stabilities;
|
$stabilities = BasePackage::$stabilities;
|
||||||
foreach ($requires as $reqName => $reqVersion) {
|
foreach ($requires as $reqName => $reqVersion) {
|
||||||
// parse explicit stability flags
|
// parse explicit stability flags
|
||||||
if (preg_match('{^[^,\s]*?@('.implode('|', $stabilities).')$}i', $reqVersion, $match)) {
|
if (preg_match('{^[^,\s]*?@('.implode('|', array_keys($stabilities)).')$}i', $reqVersion, $match)) {
|
||||||
$name = strtolower($reqName);
|
$name = strtolower($reqName);
|
||||||
$stability = array_search(VersionParser::normalizeStability($match[1]), $stabilities);
|
$stability = $stabilities[VersionParser::normalizeStability($match[1])];
|
||||||
|
|
||||||
if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) {
|
if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -135,7 +135,7 @@ class RootPackageLoader extends ArrayLoader
|
||||||
// infer flags for requirements that have an explicit -dev or -beta version specified for example
|
// infer flags for requirements that have an explicit -dev or -beta version specified for example
|
||||||
if (preg_match('{^[^,\s@]+$}', $reqVersion) && 'stable' !== ($stabilityName = VersionParser::parseStability($reqVersion))) {
|
if (preg_match('{^[^,\s@]+$}', $reqVersion) && 'stable' !== ($stabilityName = VersionParser::parseStability($reqVersion))) {
|
||||||
$name = strtolower($reqName);
|
$name = strtolower($reqName);
|
||||||
$stability = array_search($stabilityName, $stabilities);
|
$stability = $stabilities[$stabilityName];
|
||||||
if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) {
|
if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ class MemoryPackage extends BasePackage
|
||||||
protected $prettyAlias;
|
protected $prettyAlias;
|
||||||
protected $dev;
|
protected $dev;
|
||||||
|
|
||||||
|
// TODO BC change dev to stable end of june?
|
||||||
protected $minimumStability = 'dev';
|
protected $minimumStability = 'dev';
|
||||||
protected $stabilityFlags = array();
|
protected $stabilityFlags = array();
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ class VersionParser
|
||||||
*/
|
*/
|
||||||
public function parseConstraints($constraints)
|
public function parseConstraints($constraints)
|
||||||
{
|
{
|
||||||
if (preg_match('{^([^,\s]*?)@('.implode('|', BasePackage::$stabilities).')$}i', $constraints, $match)) {
|
if (preg_match('{^([^,\s]*?)@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $constraints, $match)) {
|
||||||
$constraints = empty($match[1]) ? '*' : $match[1];
|
$constraints = empty($match[1]) ? '*' : $match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Test\DependencyResolver;
|
||||||
|
|
||||||
use Composer\DependencyResolver\Pool;
|
use Composer\DependencyResolver\Pool;
|
||||||
use Composer\Repository\ArrayRepository;
|
use Composer\Repository\ArrayRepository;
|
||||||
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Test\TestCase;
|
use Composer\Test\TestCase;
|
||||||
|
|
||||||
class PoolTest extends TestCase
|
class PoolTest extends TestCase
|
||||||
|
@ -31,6 +32,22 @@ class PoolTest extends TestCase
|
||||||
$this->assertEquals(array($package), $pool->whatProvides('foo'));
|
$this->assertEquals(array($package), $pool->whatProvides('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPoolIgnoresIrrelevantPackages()
|
||||||
|
{
|
||||||
|
$pool = new Pool('stable', array('bar' => BasePackage::STABILITY_BETA));
|
||||||
|
$repo = new ArrayRepository;
|
||||||
|
$repo->addPackage($package = $this->getPackage('bar', '1'));
|
||||||
|
$repo->addPackage($betaPackage = $this->getPackage('bar', '1-beta'));
|
||||||
|
$repo->addPackage($alphaPackage = $this->getPackage('bar', '1-alpha'));
|
||||||
|
$repo->addPackage($package2 = $this->getPackage('foo', '1'));
|
||||||
|
$repo->addPackage($rcPackage2 = $this->getPackage('foo', '1rc'));
|
||||||
|
|
||||||
|
$pool->addRepository($repo);
|
||||||
|
|
||||||
|
$this->assertEquals(array($package, $betaPackage), $pool->whatProvides('bar'));
|
||||||
|
$this->assertEquals(array($package2), $pool->whatProvides('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue