Merge pull request #1836 from Seldaek/emptyconstraint

Add EmptyConstraint
main
Nils Adermann 11 years ago
commit 81b7a64778

@ -0,0 +1,47 @@
<?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\Package\LinkConstraint;
/**
* Defines an absence of constraints
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class EmptyConstraint implements LinkConstraintInterface
{
protected $prettyString;
public function matches(LinkConstraintInterface $provider)
{
return true;
}
public function setPrettyString($prettyString)
{
$this->prettyString = $prettyString;
}
public function getPrettyString()
{
if ($this->prettyString) {
return $this->prettyString;
}
return $this->__toString();
}
public function __toString()
{
return '[]';
}
}

@ -15,6 +15,7 @@ namespace Composer\Package\Version;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Package\Link;
use Composer\Package\LinkConstraint\EmptyConstraint;
use Composer\Package\LinkConstraint\MultiConstraint;
use Composer\Package\LinkConstraint\VersionConstraint;
@ -253,7 +254,7 @@ class VersionParser
}
if (preg_match('{^[x*](\.[x*])*$}i', $constraint)) {
return array();
return array(new EmptyConstraint);
}
if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}i', $constraint, $matches)) {

@ -15,6 +15,7 @@ namespace Composer\Test\Package\Version;
use Composer\Package\Version\VersionParser;
use Composer\Package\LinkConstraint\MultiConstraint;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Package\LinkConstraint\EmptyConstraint;
use Composer\Package\PackageInterface;
class VersionParserTest extends \PHPUnit_Framework_TestCase
@ -192,10 +193,10 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
public function simpleConstraints()
{
return array(
'match any' => array('*', new MultiConstraint(array())),
'match any/2' => array('*.*', new MultiConstraint(array())),
'match any/3' => array('*.x.*', new MultiConstraint(array())),
'match any/4' => array('x.x.x.*', new MultiConstraint(array())),
'match any' => array('*', new EmptyConstraint()),
'match any/2' => array('*.*', new EmptyConstraint()),
'match any/3' => array('*.x.*', new EmptyConstraint()),
'match any/4' => array('x.x.x.*', new EmptyConstraint()),
'not equal' => array('<>1.0.0', new VersionConstraint('<>', '1.0.0.0')),
'not equal/2' => array('!=1.0.0', new VersionConstraint('!=', '1.0.0.0')),
'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')),

Loading…
Cancel
Save