VersionConstraintTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Package\LinkConstraint;
  12. use Composer\Package\LinkConstraint\VersionConstraint;
  13. class VersionConstraintTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public static function successfulVersionMatches()
  16. {
  17. return array(
  18. // require provide
  19. array('==', '1', '==', '1'),
  20. array('>=', '1', '>=', '2'),
  21. array('>=', '2', '>=', '1'),
  22. array('>=', '2', '>', '1'),
  23. array('<=', '2', '>=', '1'),
  24. array('>=', '1', '<=', '2'),
  25. array('==', '2', '>=', '2'),
  26. );
  27. }
  28. /**
  29. * @dataProvider successfulVersionMatches
  30. */
  31. public function testVersionMatchSucceeds($requireOperator, $requireVersion, $provideOperator, $provideVersion)
  32. {
  33. $versionRequire = new VersionConstraint($requireOperator, $requireVersion);
  34. $versionProvide = new VersionConstraint($provideOperator, $provideVersion);
  35. $this->assertTrue($versionRequire->matches($versionProvide));
  36. }
  37. public static function failingVersionMatches()
  38. {
  39. return array(
  40. // require provide
  41. array('==', '1', '==', '2'),
  42. array('>=', '2', '<=', '1'),
  43. array('>=', '2', '<', '2'),
  44. array('<=', '2', '>', '2'),
  45. array('>', '2', '<=', '2'),
  46. array('<=', '1', '>=', '2'),
  47. array('>=', '2', '<=', '1'),
  48. array('==', '2', '<', '2'),
  49. );
  50. }
  51. /**
  52. * @dataProvider failingVersionMatches
  53. */
  54. public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion)
  55. {
  56. $versionRequire = new VersionConstraint($requireOperator, $requireVersion);
  57. $versionProvide = new VersionConstraint($provideOperator, $provideVersion);
  58. $this->assertFalse($versionRequire->matches($versionProvide));
  59. }
  60. }