2011-09-25 21:09:54 +00:00
|
|
|
<?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\Package\Version;
|
|
|
|
|
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
use Composer\Package\LinkConstraint\MultiConstraint;
|
|
|
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
|
|
|
|
|
|
|
class VersionParserTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider successfulNormalizedVersions
|
|
|
|
*/
|
|
|
|
public function testNormalizeSucceeds($input, $expected)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
2011-09-28 22:50:01 +00:00
|
|
|
$this->assertSame($expected, $parser->normalize($input));
|
2011-09-25 21:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function successfulNormalizedVersions()
|
|
|
|
{
|
|
|
|
return array(
|
2011-09-25 22:59:32 +00:00
|
|
|
'none' => array('1.0.0', '1.0.0.0'),
|
2011-09-28 22:50:01 +00:00
|
|
|
'none/2' => array('1.2.3.4', '1.2.3.4'),
|
2011-09-25 22:59:32 +00:00
|
|
|
'parses state' => array('1.0.0RC1dev', '1.0.0.0-RC1-dev'),
|
|
|
|
'CI parsing' => array('1.0.0-rC15-dev', '1.0.0.0-RC15-dev'),
|
|
|
|
'delimiters' => array('1.0.0.RC.15-dev', '1.0.0.0-RC15-dev'),
|
2011-09-26 18:34:30 +00:00
|
|
|
'RC uppercase' => array('1.0.0-rc1', '1.0.0.0-RC1'),
|
|
|
|
'patch replace' => array('1.0.0.pl3-dev', '1.0.0.0-patch3-dev'),
|
2011-09-25 22:59:32 +00:00
|
|
|
'forces w.x.y.z' => array('1.0-dev', '1.0.0.0-dev'),
|
2011-09-28 22:50:01 +00:00
|
|
|
'forces w.x.y.z/2' => array('0', '0.0.0.0'),
|
2011-09-25 22:59:32 +00:00
|
|
|
'parses long' => array('10.4.13-beta', '10.4.13.0-beta'),
|
2011-09-28 22:50:01 +00:00
|
|
|
'strips leading v' => array('v1.0.0', '1.0.0.0'),
|
|
|
|
'strips v/datetime' => array('v20100102', '20100102'),
|
2011-09-25 22:59:32 +00:00
|
|
|
'parses dates y-m' => array('2010.01', '2010-01'),
|
2011-09-25 21:09:54 +00:00
|
|
|
'parses dates w/ .' => array('2010.01.02', '2010-01-02'),
|
|
|
|
'parses dates w/ -' => array('2010-01-02', '2010-01-02'),
|
|
|
|
'parses numbers' => array('2010-01-02.5', '2010-01-02-5'),
|
|
|
|
'parses datetime' => array('20100102-203040', '20100102-203040'),
|
|
|
|
'parses dt+number' => array('20100102203040-10', '20100102203040-10'),
|
2011-09-25 22:59:32 +00:00
|
|
|
'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'),
|
2011-10-11 07:30:10 +00:00
|
|
|
'parses master' => array('master', '9999999-dev'),
|
|
|
|
'parses trunk' => array('trunk', '9999999-dev'),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider failingNormalizedVersions
|
|
|
|
* @expectedException UnexpectedValueException
|
|
|
|
*/
|
|
|
|
public function testNormalizeFails($input)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$parser->normalize($input);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function failingNormalizedVersions()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'empty ' => array(''),
|
|
|
|
'invalid chars' => array('a'),
|
|
|
|
'invalid type' => array('1.0.0-meh'),
|
2011-09-25 22:59:32 +00:00
|
|
|
'too many bits' => array('1.0.0.0.0'),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-10-11 07:30:10 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider successfulNormalizedBranches
|
|
|
|
*/
|
|
|
|
public function testNormalizeBranch($input, $expected)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$this->assertSame((string) $expected, (string) $parser->normalizeBranch($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function successfulNormalizedBranches()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'parses x' => array('v1.x', '1.9999999.9999999.9999999-dev'),
|
|
|
|
'parses *' => array('v1.*', '1.9999999.9999999.9999999-dev'),
|
|
|
|
'parses digits' => array('v1.0', '1.0.9999999.9999999-dev'),
|
|
|
|
'parses long x' => array('v1.0.x', '1.0.9999999.9999999-dev'),
|
|
|
|
'parses long *' => array('v1.0.3.*', '1.0.3.9999999-dev'),
|
|
|
|
'parses long digits' => array('v2.4.0', '2.4.0.9999999-dev'),
|
|
|
|
'parses long digits/2' => array('2.4.4', '2.4.4.9999999-dev'),
|
|
|
|
'parses master' => array('master', '9999999-dev'),
|
|
|
|
'parses trunk' => array('trunk', '9999999-dev'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-25 21:09:54 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider simpleConstraints
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsSimple($input, $expected)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
2011-09-28 22:50:01 +00:00
|
|
|
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
2011-09-25 21:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function simpleConstraints()
|
|
|
|
{
|
|
|
|
return array(
|
2011-09-25 22:59:32 +00:00
|
|
|
'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')),
|
|
|
|
'lesser than' => array('<1.2.3.4', new VersionConstraint('<', '1.2.3.4')),
|
|
|
|
'less/eq than' => array('<=1.2.3', new VersionConstraint('<=', '1.2.3.0')),
|
|
|
|
'great/eq than' => array('>=1.2.3', new VersionConstraint('>=', '1.2.3.0')),
|
|
|
|
'equals' => array('=1.2.3', new VersionConstraint('=', '1.2.3.0')),
|
|
|
|
'double equals' => array('==1.2.3', new VersionConstraint('=', '1.2.3.0')),
|
|
|
|
'no op means eq' => array('1.2.3', new VersionConstraint('=', '1.2.3.0')),
|
|
|
|
'completes version' => array('=1.0', new VersionConstraint('=', '1.0.0.0')),
|
|
|
|
'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0')),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider wildcardConstraints
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsWildcard($input, $min, $max)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$expected = new MultiConstraint(array($min, $max));
|
|
|
|
|
2011-09-28 22:50:01 +00:00
|
|
|
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
2011-09-25 21:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function wildcardConstraints()
|
|
|
|
{
|
|
|
|
return array(
|
2011-09-28 22:50:01 +00:00
|
|
|
array('2.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.9999999.9999999.9999999')),
|
|
|
|
array('20.*', new VersionConstraint('>=', '20.0.0.0'), new VersionConstraint('<', '20.9999999.9999999.9999999')),
|
|
|
|
array('2.0.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.0.9999999.9999999')),
|
|
|
|
array('2.2.*', new VersionConstraint('>=', '2.2.0.0'), new VersionConstraint('<', '2.2.9999999.9999999')),
|
|
|
|
array('2.10.*', new VersionConstraint('>=', '2.10.0.0'), new VersionConstraint('<', '2.10.9999999.9999999')),
|
|
|
|
array('2.1.3.*', new VersionConstraint('>=', '2.1.3.0'), new VersionConstraint('<', '2.1.3.9999999')),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-25 22:59:32 +00:00
|
|
|
public function testParseConstraintsMulti()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$first = new VersionConstraint('>', '2.0.0.0');
|
|
|
|
$second = new VersionConstraint('<=', '3.0.0.0');
|
|
|
|
$multi = new MultiConstraint(array($first, $second));
|
2011-09-28 22:50:01 +00:00
|
|
|
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0,<=3.0'));
|
2011-09-25 22:59:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 21:09:54 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider failingConstraints
|
|
|
|
* @expectedException UnexpectedValueException
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsFails($input)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$parser->parseConstraints($input);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function failingConstraints()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'empty ' => array(''),
|
|
|
|
'invalid version' => array('1.0.0-meh'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|