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;
|
|
|
|
|
2015-06-02 01:21:06 +00:00
|
|
|
use Composer\Package\Link;
|
2011-09-25 21:09:54 +00:00
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
use Composer\Package\LinkConstraint\MultiConstraint;
|
|
|
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
2013-04-27 12:32:22 +00:00
|
|
|
use Composer\Package\LinkConstraint\EmptyConstraint;
|
2012-08-30 21:01:21 +00:00
|
|
|
use Composer\Package\PackageInterface;
|
2011-09-25 21:09:54 +00:00
|
|
|
|
|
|
|
class VersionParserTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2012-08-30 22:44:54 +00:00
|
|
|
|
2011-09-25 21:09:54 +00:00
|
|
|
/**
|
2015-01-20 10:26:10 +00:00
|
|
|
* @dataProvider numericAliasVersions
|
2011-09-25 21:09:54 +00:00
|
|
|
*/
|
2015-01-20 10:26:10 +00:00
|
|
|
public function testParseNumericAliasPrefix($input, $expected)
|
2011-09-25 21:09:54 +00:00
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
2015-01-20 10:26:10 +00:00
|
|
|
$this->assertSame($expected, $parser->parseNumericAliasPrefix($input));
|
2011-09-25 21:09:54 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 10:26:10 +00:00
|
|
|
public function numericAliasVersions()
|
|
|
|
{
|
2014-12-01 05:09:35 +00:00
|
|
|
return array(
|
|
|
|
array('0.x-dev', '0.'),
|
|
|
|
array('1.0.x-dev', '1.0.'),
|
|
|
|
array('1.x-dev', '1.'),
|
|
|
|
array('1.2.x-dev', '1.2.'),
|
2015-01-20 10:26:10 +00:00
|
|
|
array('1.2-dev', '1.2.'),
|
|
|
|
array('1-dev', '1.'),
|
2014-12-01 05:09:35 +00:00
|
|
|
array('dev-develop', false),
|
|
|
|
array('dev-master', false),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-20 10:26:10 +00:00
|
|
|
* @dataProvider successfulNormalizedVersions
|
2014-12-01 05:09:35 +00:00
|
|
|
*/
|
2015-01-20 10:26:10 +00:00
|
|
|
public function testNormalizeSucceeds($input, $expected)
|
2014-12-01 05:09:35 +00:00
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
2015-01-20 10:26:10 +00:00
|
|
|
$this->assertSame($expected, $parser->normalize($input));
|
2014-12-01 05:09:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 21:09:54 +00:00
|
|
|
public function successfulNormalizedVersions()
|
|
|
|
{
|
|
|
|
return array(
|
2014-09-22 09:58:26 +00:00
|
|
|
'none' => array('1.0.0', '1.0.0.0'),
|
|
|
|
'none/2' => array('1.2.3.4', '1.2.3.4'),
|
|
|
|
'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'),
|
|
|
|
'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'),
|
|
|
|
'forces w.x.y.z' => array('1.0-dev', '1.0.0.0-dev'),
|
|
|
|
'forces w.x.y.z/2' => array('0', '0.0.0.0'),
|
|
|
|
'parses long' => array('10.4.13-beta', '10.4.13.0-beta'),
|
2014-10-06 11:41:54 +00:00
|
|
|
'parses long/2' => array('10.4.13beta2', '10.4.13.0-beta2'),
|
2014-12-08 12:57:51 +00:00
|
|
|
'parses long/semver' => array('10.4.13beta.2', '10.4.13.0-beta2'),
|
2014-09-22 09:58:26 +00:00
|
|
|
'expand shorthand' => array('10.4.13-b', '10.4.13.0-beta'),
|
|
|
|
'expand shorthand2' => array('10.4.13-b5', '10.4.13.0-beta5'),
|
|
|
|
'strips leading v' => array('v1.0.0', '1.0.0.0'),
|
|
|
|
'strips v/datetime' => array('v20100102', '20100102'),
|
|
|
|
'parses dates y-m' => array('2010.01', '2010-01'),
|
|
|
|
'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 dates y.m.Y' => array('2010.1.555', '2010.1.555.0'),
|
|
|
|
'parses datetime' => array('20100102-203040', '20100102-203040'),
|
|
|
|
'parses dt+number' => array('20100102203040-10', '20100102203040-10'),
|
|
|
|
'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'),
|
|
|
|
'parses master' => array('dev-master', '9999999-dev'),
|
|
|
|
'parses trunk' => array('dev-trunk', '9999999-dev'),
|
|
|
|
'parses branches' => array('1.x-dev', '1.9999999.9999999.9999999-dev'),
|
|
|
|
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
|
|
|
|
'parses arbitrary2' => array('DEV-FOOBAR', 'dev-FOOBAR'),
|
|
|
|
'parses arbitrary3' => array('dev-feature/foo', 'dev-feature/foo'),
|
|
|
|
'ignores aliases' => array('dev-master as 1.0.0', '9999999-dev'),
|
2014-12-08 15:52:32 +00:00
|
|
|
'semver metadata' => array('dev-master+foo.bar', '9999999-dev'),
|
|
|
|
'semver metadata/2' => array('1.0.0-beta.5+foo', '1.0.0.0-beta5'),
|
|
|
|
'semver metadata/3' => array('1.0.0+foo', '1.0.0.0'),
|
|
|
|
'metadata w/ alias' => array('1.0.0+foo as 2.0', '1.0.0.0'),
|
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'),
|
2012-02-18 16:43:12 +00:00
|
|
|
'non-dev arbitrary' => array('feature-foo'),
|
2014-12-08 15:52:32 +00:00
|
|
|
'metadata w/ space' => array('1.0.0+foo bar'),
|
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'),
|
2011-11-20 20:20:03 +00:00
|
|
|
'parses digits/2' => array('2.0', '2.0.9999999.9999999-dev'),
|
2011-10-11 07:30:10 +00:00
|
|
|
'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'),
|
2012-02-18 16:43:12 +00:00
|
|
|
'parses arbitrary' => array('feature-a', 'dev-feature-a'),
|
2012-08-11 16:27:43 +00:00
|
|
|
'parses arbitrary/2' => array('FOOBAR', 'dev-FOOBAR'),
|
2011-10-11 07:30:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-23 21:53:34 +00:00
|
|
|
public function testParseConstraintsIgnoresStabilityFlag()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$this->assertSame((string) new VersionConstraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0@dev'));
|
|
|
|
}
|
|
|
|
|
2012-05-16 15:14:56 +00:00
|
|
|
public function testParseConstraintsIgnoresReferenceOnDevVersion()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$this->assertSame((string) new VersionConstraint('=', '1.0.9999999.9999999-dev'), (string) $parser->parseConstraints('1.0.x-dev#abcd123'));
|
2013-02-13 12:26:27 +00:00
|
|
|
$this->assertSame((string) new VersionConstraint('=', '1.0.9999999.9999999-dev'), (string) $parser->parseConstraints('1.0.x-dev#trunk/@123'));
|
2012-05-16 15:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException UnexpectedValueException
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsFailsOnBadReference()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$this->assertSame((string) new VersionConstraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0#abcd123'));
|
2013-02-13 12:26:27 +00:00
|
|
|
$this->assertSame((string) new VersionConstraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0#trunk/@123'));
|
2012-05-16 15:14:56 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 10:57:37 +00:00
|
|
|
/**
|
|
|
|
* @expectedException UnexpectedValueException
|
|
|
|
* @expectedExceptionMessage Invalid operator "~>", you probably meant to use the "~" operator
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsNudgesRubyDevsTowardsThePathOfRighteousness()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$parser->parseConstraints('~>1.2');
|
|
|
|
}
|
|
|
|
|
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(
|
2013-04-27 12:32:22 +00:00
|
|
|
'match any' => array('*', new EmptyConstraint()),
|
|
|
|
'match any/2' => array('*.*', new EmptyConstraint()),
|
|
|
|
'match any/3' => array('*.x.*', new EmptyConstraint()),
|
2014-12-08 12:57:51 +00:00
|
|
|
'match any/4' => array('x.X.x.*', new EmptyConstraint()),
|
2012-06-19 01:08:36 +00:00
|
|
|
'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')),
|
2011-09-25 22:59:32 +00:00
|
|
|
'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')),
|
2012-10-06 14:32:16 +00:00
|
|
|
'lesser than' => array('<1.2.3.4', new VersionConstraint('<', '1.2.3.4-dev')),
|
2011-09-25 22:59:32 +00:00
|
|
|
'less/eq than' => array('<=1.2.3', new VersionConstraint('<=', '1.2.3.0')),
|
2015-06-30 10:21:49 +00:00
|
|
|
'great/eq than' => array('>=1.2.3', new VersionConstraint('>=', '1.2.3.0-dev')),
|
2011-09-25 22:59:32 +00:00
|
|
|
'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')),
|
2013-04-04 15:35:55 +00:00
|
|
|
'shorthand beta' => array('1.2.3b5', new VersionConstraint('=', '1.2.3.0-beta5')),
|
2015-06-30 10:21:49 +00:00
|
|
|
'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0-dev')),
|
2014-01-15 15:47:27 +00:00
|
|
|
'accepts spaces/2' => array('< 1.2.3', new VersionConstraint('<', '1.2.3.0-dev')),
|
|
|
|
'accepts spaces/3' => array('> 1.2.3', new VersionConstraint('>', '1.2.3.0')),
|
2012-02-18 18:00:40 +00:00
|
|
|
'accepts master' => array('>=dev-master', new VersionConstraint('>=', '9999999-dev')),
|
|
|
|
'accepts master/2' => array('dev-master', new VersionConstraint('=', '9999999-dev')),
|
|
|
|
'accepts arbitrary' => array('dev-feature-a', new VersionConstraint('=', 'dev-feature-a')),
|
2012-04-09 14:00:02 +00:00
|
|
|
'regression #550' => array('dev-some-fix', new VersionConstraint('=', 'dev-some-fix')),
|
2012-08-11 16:27:43 +00:00
|
|
|
'regression #935' => array('dev-CAPS', new VersionConstraint('=', 'dev-CAPS')),
|
2012-05-24 21:29:08 +00:00
|
|
|
'ignores aliases' => array('dev-master as 1.0.0', new VersionConstraint('=', '9999999-dev')),
|
2012-10-06 14:32:16 +00:00
|
|
|
'lesser than override' => array('<1.2.3.4-stable', new VersionConstraint('<', '1.2.3.4')),
|
2015-06-30 10:21:49 +00:00
|
|
|
'great/eq than override' => array('>=1.2.3.4-stable', new VersionConstraint('>=', '1.2.3.4')),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider wildcardConstraints
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsWildcard($input, $min, $max)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
2011-11-23 15:41:27 +00:00
|
|
|
if ($min) {
|
|
|
|
$expected = new MultiConstraint(array($min, $max));
|
|
|
|
} else {
|
|
|
|
$expected = $max;
|
|
|
|
}
|
2011-09-25 21:09:54 +00:00
|
|
|
|
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(
|
2013-05-20 07:10:04 +00:00
|
|
|
array('2.*', new VersionConstraint('>=', '2.0.0.0-dev'), new VersionConstraint('<', '3.0.0.0-dev')),
|
|
|
|
array('20.*', new VersionConstraint('>=', '20.0.0.0-dev'), new VersionConstraint('<', '21.0.0.0-dev')),
|
|
|
|
array('2.0.*', new VersionConstraint('>=', '2.0.0.0-dev'), new VersionConstraint('<', '2.1.0.0-dev')),
|
|
|
|
array('2.2.x', new VersionConstraint('>=', '2.2.0.0-dev'), new VersionConstraint('<', '2.3.0.0-dev')),
|
2014-12-08 12:57:51 +00:00
|
|
|
array('2.10.X', new VersionConstraint('>=', '2.10.0.0-dev'), new VersionConstraint('<', '2.11.0.0-dev')),
|
2013-05-20 07:10:04 +00:00
|
|
|
array('2.1.3.*', new VersionConstraint('>=', '2.1.3.0-dev'), new VersionConstraint('<', '2.1.4.0-dev')),
|
|
|
|
array('0.*', null, new VersionConstraint('<', '1.0.0.0-dev')),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-29 23:27:38 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider tildeConstraints
|
|
|
|
*/
|
|
|
|
public function testParseTildeWildcard($input, $min, $max)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
if ($min) {
|
|
|
|
$expected = new MultiConstraint(array($min, $max));
|
|
|
|
} else {
|
|
|
|
$expected = $max;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tildeConstraints()
|
|
|
|
{
|
|
|
|
return array(
|
2013-05-20 07:02:40 +00:00
|
|
|
array('~1', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('~1.0', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('~1.0.0', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '1.1.0.0-dev')),
|
|
|
|
array('~1.2', new VersionConstraint('>=', '1.2.0.0-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('~1.2.3', new VersionConstraint('>=', '1.2.3.0-dev'), new VersionConstraint('<', '1.3.0.0-dev')),
|
|
|
|
array('~1.2.3.4', new VersionConstraint('>=', '1.2.3.4-dev'), new VersionConstraint('<', '1.2.4.0-dev')),
|
2013-01-13 15:36:19 +00:00
|
|
|
array('~1.2-beta',new VersionConstraint('>=', '1.2.0.0-beta'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('~1.2-b2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
2013-02-11 10:52:50 +00:00
|
|
|
array('~1.2-BETA2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
2013-01-13 15:36:19 +00:00
|
|
|
array('~1.2.2-dev', new VersionConstraint('>=', '1.2.2.0-dev'), new VersionConstraint('<', '1.3.0.0-dev')),
|
2013-08-12 00:22:32 +00:00
|
|
|
array('~1.2.2-stable', new VersionConstraint('>=', '1.2.2.0-stable'), new VersionConstraint('<', '1.3.0.0-dev')),
|
2012-09-29 23:27:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-08 15:39:52 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider caretConstraints
|
|
|
|
*/
|
|
|
|
public function testParseCaretWildcard($input, $min, $max)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
if ($min) {
|
|
|
|
$expected = new MultiConstraint(array($min, $max));
|
|
|
|
} else {
|
|
|
|
$expected = $max;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function caretConstraints()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('^1', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('^0', new VersionConstraint('>=', '0.0.0.0-dev'), new VersionConstraint('<', '1.0.0.0-dev')),
|
|
|
|
array('^0.0', new VersionConstraint('>=', '0.0.0.0-dev'), new VersionConstraint('<', '0.1.0.0-dev')),
|
|
|
|
array('^1.2', new VersionConstraint('>=', '1.2.0.0-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('^1.2.3-beta.2', new VersionConstraint('>=', '1.2.3.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('^1.2.3.4', new VersionConstraint('>=', '1.2.3.4-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('^1.2.3', new VersionConstraint('>=', '1.2.3.0-dev'), new VersionConstraint('<', '2.0.0.0-dev')),
|
|
|
|
array('^0.2.3', new VersionConstraint('>=', '0.2.3.0-dev'), new VersionConstraint('<', '0.3.0.0-dev')),
|
|
|
|
array('^0.2', new VersionConstraint('>=', '0.2.0.0-dev'), new VersionConstraint('<', '0.3.0.0-dev')),
|
2014-12-08 16:27:47 +00:00
|
|
|
array('^0.2.0', new VersionConstraint('>=', '0.2.0.0-dev'), new VersionConstraint('<', '0.3.0.0-dev')),
|
2014-12-08 15:39:52 +00:00
|
|
|
array('^0.0.3', new VersionConstraint('>=', '0.0.3.0-dev'), new VersionConstraint('<', '0.0.4.0-dev')),
|
|
|
|
array('^0.0.3-alpha', new VersionConstraint('>=', '0.0.3.0-alpha'), new VersionConstraint('<', '0.0.4.0-dev')),
|
|
|
|
array('^0.0.3-dev', new VersionConstraint('>=', '0.0.3.0-dev'), new VersionConstraint('<', '0.0.4.0-dev')),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-08 13:44:42 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider hyphenConstraints
|
|
|
|
*/
|
|
|
|
public function testParseHyphen($input, $min, $max)
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
if ($min) {
|
|
|
|
$expected = new MultiConstraint(array($min, $max));
|
|
|
|
} else {
|
|
|
|
$expected = $max;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hyphenConstraints()
|
|
|
|
{
|
|
|
|
return array(
|
2015-06-02 12:03:45 +00:00
|
|
|
array('1 - 2', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '3.0.0.0-dev')),
|
|
|
|
array('1.2.3 - 2.3.4.5', new VersionConstraint('>=', '1.2.3.0-dev'), new VersionConstraint('<=', '2.3.4.5')),
|
|
|
|
array('1.2-beta - 2.3', new VersionConstraint('>=', '1.2.0.0-beta'), new VersionConstraint('<', '2.4.0.0-dev')),
|
|
|
|
array('1.2-beta - 2.3-dev', new VersionConstraint('>=', '1.2.0.0-beta'), new VersionConstraint('<=', '2.3.0.0-dev')),
|
|
|
|
array('1.2-RC - 2.3.1', new VersionConstraint('>=', '1.2.0.0-RC'), new VersionConstraint('<=', '2.3.1.0')),
|
|
|
|
array('1.2.3-alpha - 2.3-RC', new VersionConstraint('>=', '1.2.3.0-alpha'), new VersionConstraint('<=', '2.3.0.0-RC')),
|
2015-06-02 12:20:48 +00:00
|
|
|
array('1 - 2.0', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '2.1.0.0-dev')),
|
2015-06-02 12:03:45 +00:00
|
|
|
array('1 - 2.1', new VersionConstraint('>=', '1.0.0.0-dev'), new VersionConstraint('<', '2.2.0.0-dev')),
|
|
|
|
array('1.2 - 2.1.0', new VersionConstraint('>=', '1.2.0.0-dev'), new VersionConstraint('<=', '2.1.0.0')),
|
2015-06-02 12:20:48 +00:00
|
|
|
array('1.3 - 2.1.3', new VersionConstraint('>=', '1.3.0.0-dev'), new VersionConstraint('<=', '2.1.3.0')),
|
2014-12-08 13:44:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-01-15 15:47:27 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider multiConstraintProvider
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsMulti($constraint)
|
2011-09-25 22:59:32 +00:00
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$first = new VersionConstraint('>', '2.0.0.0');
|
|
|
|
$second = new VersionConstraint('<=', '3.0.0.0');
|
|
|
|
$multi = new MultiConstraint(array($first, $second));
|
2014-01-15 15:47:27 +00:00
|
|
|
$this->assertSame((string) $multi, (string) $parser->parseConstraints($constraint));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function multiConstraintProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('>2.0,<=3.0'),
|
|
|
|
array('>2.0 <=3.0'),
|
2014-12-08 12:57:51 +00:00
|
|
|
array('>2.0 <=3.0'),
|
2014-01-15 15:47:27 +00:00
|
|
|
array('>2.0, <=3.0'),
|
|
|
|
array('>2.0 ,<=3.0'),
|
|
|
|
array('>2.0 , <=3.0'),
|
2014-01-15 16:13:42 +00:00
|
|
|
array('>2.0 , <=3.0'),
|
|
|
|
array('> 2.0 <= 3.0'),
|
|
|
|
array('> 2.0 , <= 3.0'),
|
|
|
|
array(' > 2.0 , <= 3.0 '),
|
2014-01-15 15:47:27 +00:00
|
|
|
);
|
2011-09-25 22:59:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-07 17:46:04 +00:00
|
|
|
public function testParseConstraintsMultiWithStabilitySuffix()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$first = new VersionConstraint('>=', '1.1.0.0-alpha4');
|
|
|
|
$second = new VersionConstraint('<', '1.2.9999999.9999999-dev');
|
|
|
|
$multi = new MultiConstraint(array($first, $second));
|
|
|
|
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>=1.1.0-alpha4,<1.2.x-dev'));
|
|
|
|
|
|
|
|
$first = new VersionConstraint('>=', '1.1.0.0-alpha4');
|
|
|
|
$second = new VersionConstraint('<', '1.2.0.0-beta2');
|
|
|
|
$multi = new MultiConstraint(array($first, $second));
|
|
|
|
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>=1.1.0-alpha4,<1.2-beta2'));
|
|
|
|
}
|
|
|
|
|
2014-12-08 12:57:51 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider multiConstraintProvider2
|
|
|
|
*/
|
|
|
|
public function testParseConstraintsMultiDisjunctiveHasPrioOverConjuctive($constraint)
|
2013-04-27 13:20:35 +00:00
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$first = new VersionConstraint('>', '2.0.0.0');
|
|
|
|
$second = new VersionConstraint('<', '2.0.5.0-dev');
|
|
|
|
$third = new VersionConstraint('>', '2.0.6.0');
|
|
|
|
$multi1 = new MultiConstraint(array($first, $second));
|
|
|
|
$multi2 = new MultiConstraint(array($multi1, $third), false);
|
2014-12-08 12:57:51 +00:00
|
|
|
$this->assertSame((string) $multi2, (string) $parser->parseConstraints($constraint));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function multiConstraintProvider2()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('>2.0,<2.0.5 | >2.0.6'),
|
|
|
|
array('>2.0,<2.0.5 || >2.0.6'),
|
|
|
|
array('> 2.0 , <2.0.5 | > 2.0.6'),
|
|
|
|
);
|
2013-04-27 13:20:35 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 17:05:39 +00:00
|
|
|
public function testParseConstraintsMultiWithStabilities()
|
|
|
|
{
|
|
|
|
$parser = new VersionParser;
|
|
|
|
$first = new VersionConstraint('>', '2.0.0.0');
|
|
|
|
$second = new VersionConstraint('<=', '3.0.0.0-dev');
|
|
|
|
$multi = new MultiConstraint(array($first, $second));
|
|
|
|
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0@stable,<=3.0@dev'));
|
|
|
|
}
|
|
|
|
|
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'),
|
2014-01-15 16:13:42 +00:00
|
|
|
'operator abuse' => array('>2.0,,<=3.0'),
|
|
|
|
'operator abuse/2' => array('>2.0 ,, <=3.0'),
|
2014-12-08 12:57:51 +00:00
|
|
|
'operator abuse/3' => array('>2.0 ||| <=3.0'),
|
2011-09-25 21:09:54 +00:00
|
|
|
);
|
|
|
|
}
|
2012-03-03 13:07:13 +00:00
|
|
|
|
|
|
|
/**
|
2012-04-17 23:17:32 +00:00
|
|
|
* @dataProvider stabilityProvider
|
2012-03-03 13:07:13 +00:00
|
|
|
*/
|
2012-04-17 23:17:32 +00:00
|
|
|
public function testParseStability($expected, $version)
|
2012-03-03 13:07:13 +00:00
|
|
|
{
|
2012-04-17 23:17:32 +00:00
|
|
|
$this->assertSame($expected, VersionParser::parseStability($version));
|
2012-03-03 13:07:13 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 23:17:32 +00:00
|
|
|
public function stabilityProvider()
|
2012-03-03 13:07:13 +00:00
|
|
|
{
|
|
|
|
return array(
|
2013-02-25 15:51:01 +00:00
|
|
|
array('stable', '1'),
|
2012-04-17 23:17:32 +00:00
|
|
|
array('stable', '1.0'),
|
2013-02-25 15:51:01 +00:00
|
|
|
array('stable', '3.2.1'),
|
|
|
|
array('stable', 'v3.2.1'),
|
2012-04-17 23:17:32 +00:00
|
|
|
array('dev', 'v2.0.x-dev'),
|
2012-05-16 15:14:56 +00:00
|
|
|
array('dev', 'v2.0.x-dev#abc123'),
|
2013-02-13 12:26:27 +00:00
|
|
|
array('dev', 'v2.0.x-dev#trunk/@123'),
|
2012-04-17 23:17:32 +00:00
|
|
|
array('RC', '3.0-RC2'),
|
|
|
|
array('dev', 'dev-master'),
|
|
|
|
array('dev', '3.1.2-dev'),
|
|
|
|
array('stable', '3.1.2-pl2'),
|
|
|
|
array('stable', '3.1.2-patch'),
|
|
|
|
array('alpha', '3.1.2-alpha5'),
|
|
|
|
array('beta', '3.1.2-beta'),
|
2012-09-04 13:59:29 +00:00
|
|
|
array('beta', '2.0B1'),
|
2012-07-08 21:47:40 +00:00
|
|
|
array('alpha', '1.2.0a1'),
|
|
|
|
array('alpha', '1.2_a1'),
|
2012-09-04 13:59:29 +00:00
|
|
|
array('RC', '2.0.0rc1')
|
2012-03-03 13:07:13 +00:00
|
|
|
);
|
|
|
|
}
|
2011-09-25 21:09:54 +00:00
|
|
|
}
|