1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Correct version contraint matching and add tests for various cases

This commit is contained in:
Nils Adermann 2011-04-18 22:45:11 +02:00
parent 1870291949
commit d5dd86cd75
2 changed files with 93 additions and 1 deletions

View file

@ -0,0 +1,69 @@
<?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;
use Composer\Package\LinkConstraint\VersionConstraint;
class VersionConstraintTest extends \PHPUnit_Framework_TestCase
{
static public function successfulVersionMatches()
{
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'),
);
}
/**
* @dataProvider successfulVersionMatches
*/
public function testVersionMatchSucceeds($requireOperator, $requireVersion, $provideOperator, $provideVersion)
{
$versionRequire = new VersionConstraint($requireOperator, $requireVersion);
$versionProvide = new VersionConstraint($provideOperator, $provideVersion);
$this->assertTrue($versionRequire->matches($versionProvide));
}
static public function failingVersionMatches()
{
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'),
);
}
/**
* @dataProvider failingVersionMatches
*/
public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion)
{
$versionRequire = new VersionConstraint($requireOperator, $requireVersion);
$versionProvide = new VersionConstraint($provideOperator, $provideVersion);
$this->assertFalse($versionRequire->matches($versionProvide));
}
}