VersionConstraintTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. array('!=', '1', '!=', '1'),
  27. array('!=', '1', '==', '2'),
  28. array('!=', '1', '<', '1'),
  29. array('!=', '1', '<=', '1'),
  30. array('!=', '1', '>', '1'),
  31. array('!=', '1', '>=', '1'),
  32. );
  33. }
  34. /**
  35. * @dataProvider successfulVersionMatches
  36. */
  37. public function testVersionMatchSucceeds($requireOperator, $requireVersion, $provideOperator, $provideVersion)
  38. {
  39. $versionRequire = new VersionConstraint($requireOperator, $requireVersion);
  40. $versionProvide = new VersionConstraint($provideOperator, $provideVersion);
  41. $this->assertTrue($versionRequire->matches($versionProvide));
  42. }
  43. public static function failingVersionMatches()
  44. {
  45. return array(
  46. // require provide
  47. array('==', '1', '==', '2'),
  48. array('>=', '2', '<=', '1'),
  49. array('>=', '2', '<', '2'),
  50. array('<=', '2', '>', '2'),
  51. array('>', '2', '<=', '2'),
  52. array('<=', '1', '>=', '2'),
  53. array('>=', '2', '<=', '1'),
  54. array('==', '2', '<', '2'),
  55. array('!=', '1', '==', '1'),
  56. array('==', '1', '!=', '1'),
  57. );
  58. }
  59. /**
  60. * @dataProvider failingVersionMatches
  61. */
  62. public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion)
  63. {
  64. $versionRequire = new VersionConstraint($requireOperator, $requireVersion);
  65. $versionProvide = new VersionConstraint($provideOperator, $provideVersion);
  66. $this->assertFalse($versionRequire->matches($versionProvide));
  67. }
  68. }