2011-04-18 20:45:11 +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.
|
|
|
|
*/
|
|
|
|
|
2012-03-08 13:17:22 +00:00
|
|
|
namespace Composer\Test\Package\LinkConstraint;
|
2011-04-18 20:45:11 +00:00
|
|
|
|
|
|
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
|
|
|
|
|
|
|
class VersionConstraintTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2012-06-14 10:10:01 +00:00
|
|
|
public static function successfulVersionMatches()
|
2011-04-18 20:45:11 +00:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
// require provide
|
|
|
|
array('==', '1', '==', '1'),
|
|
|
|
array('>=', '1', '>=', '2'),
|
|
|
|
array('>=', '2', '>=', '1'),
|
|
|
|
array('>=', '2', '>', '1'),
|
|
|
|
array('<=', '2', '>=', '1'),
|
|
|
|
array('>=', '1', '<=', '2'),
|
|
|
|
array('==', '2', '>=', '2'),
|
2012-06-19 12:37:29 +00:00
|
|
|
array('!=', '1', '!=', '1'),
|
|
|
|
array('!=', '1', '==', '2'),
|
|
|
|
array('!=', '1', '<', '1'),
|
|
|
|
array('!=', '1', '<=', '1'),
|
|
|
|
array('!=', '1', '>', '1'),
|
|
|
|
array('!=', '1', '>=', '1'),
|
2012-07-11 18:25:22 +00:00
|
|
|
array('==', 'dev-foo-bar', '==', 'dev-foo-bar'),
|
2012-07-11 18:48:57 +00:00
|
|
|
array('==', 'dev-foo-xyz', '==', 'dev-foo-xyz'),
|
|
|
|
array('>=', 'dev-foo-bar', '>=', 'dev-foo-xyz'),
|
|
|
|
array('<=', 'dev-foo-bar', '<', 'dev-foo-xyz'),
|
|
|
|
array('!=', 'dev-foo-bar', '<', 'dev-foo-xyz'),
|
|
|
|
array('>=', 'dev-foo-bar', '!=', 'dev-foo-bar'),
|
|
|
|
array('!=', 'dev-foo-bar', '!=', 'dev-foo-xyz'),
|
2011-04-18 20:45:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider successfulVersionMatches
|
|
|
|
*/
|
|
|
|
public function testVersionMatchSucceeds($requireOperator, $requireVersion, $provideOperator, $provideVersion)
|
|
|
|
{
|
|
|
|
$versionRequire = new VersionConstraint($requireOperator, $requireVersion);
|
|
|
|
$versionProvide = new VersionConstraint($provideOperator, $provideVersion);
|
|
|
|
|
|
|
|
$this->assertTrue($versionRequire->matches($versionProvide));
|
|
|
|
}
|
|
|
|
|
2012-06-14 10:10:01 +00:00
|
|
|
public static function failingVersionMatches()
|
2011-04-18 20:45:11 +00:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
// require provide
|
|
|
|
array('==', '1', '==', '2'),
|
|
|
|
array('>=', '2', '<=', '1'),
|
|
|
|
array('>=', '2', '<', '2'),
|
|
|
|
array('<=', '2', '>', '2'),
|
|
|
|
array('>', '2', '<=', '2'),
|
|
|
|
array('<=', '1', '>=', '2'),
|
|
|
|
array('>=', '2', '<=', '1'),
|
|
|
|
array('==', '2', '<', '2'),
|
2012-06-19 12:37:29 +00:00
|
|
|
array('!=', '1', '==', '1'),
|
|
|
|
array('==', '1', '!=', '1'),
|
2012-07-11 18:25:22 +00:00
|
|
|
array('==', 'dev-foo-dist', '==', 'dev-foo-zist'),
|
2012-07-11 18:48:57 +00:00
|
|
|
array('==', 'dev-foo-bist', '==', 'dev-foo-aist'),
|
|
|
|
array('<=', 'dev-foo-bist', '>=', 'dev-foo-aist'),
|
|
|
|
array('>=', 'dev-foo-bist', '<', 'dev-foo-aist'),
|
2011-04-18 20:45:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider failingVersionMatches
|
|
|
|
*/
|
|
|
|
public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion)
|
|
|
|
{
|
|
|
|
$versionRequire = new VersionConstraint($requireOperator, $requireVersion);
|
|
|
|
$versionProvide = new VersionConstraint($provideOperator, $provideVersion);
|
|
|
|
|
|
|
|
$this->assertFalse($versionRequire->matches($versionProvide));
|
|
|
|
}
|
|
|
|
}
|