You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.4KB

  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Fxp\Composer\AssetPlugin\Tests\Converter;
  11. use Fxp\Composer\AssetPlugin\Converter\SemverConverter;
  12. use Fxp\Composer\AssetPlugin\Converter\VersionConverterInterface;
  13. /**
  14. * Tests for the conversion of Semver syntax to composer syntax.
  15. *
  16. * @author François Pluchino <francois.pluchino@gmail.com>
  17. */
  18. class SemverConverterTest extends \PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * @var VersionConverterInterface
  22. */
  23. protected $converter;
  24. protected function setUp()
  25. {
  26. $this->converter = new SemverConverter();
  27. }
  28. protected function tearDown()
  29. {
  30. $this->converter = null;
  31. }
  32. /**
  33. * @dataProvider getTestVersions
  34. */
  35. public function testConverter($semver, $composer)
  36. {
  37. $this->assertEquals($composer, $this->converter->convertVersion($semver));
  38. if (!ctype_alpha($semver) && !in_array($semver, array(null, ''))) {
  39. $this->assertEquals('v'.$composer, $this->converter->convertVersion('v'.$semver));
  40. }
  41. }
  42. public function getTestVersions()
  43. {
  44. return array(
  45. array('1.2.3', '1.2.3'),
  46. array('1.2.3alpha', '1.2.3-alpha1'),
  47. array('1.2.3-alpha', '1.2.3-alpha1'),
  48. array('1.2.3a', '1.2.3-alpha1'),
  49. array('1.2.3a1', '1.2.3-alpha1'),
  50. array('1.2.3-a', '1.2.3-alpha1'),
  51. array('1.2.3-a1', '1.2.3-alpha1'),
  52. array('1.2.3b', '1.2.3-beta1'),
  53. array('1.2.3b1', '1.2.3-beta1'),
  54. array('1.2.3-b', '1.2.3-beta1'),
  55. array('1.2.3-b1', '1.2.3-beta1'),
  56. array('1.2.3beta', '1.2.3-beta1'),
  57. array('1.2.3-beta', '1.2.3-beta1'),
  58. array('1.2.3beta1', '1.2.3-beta1'),
  59. array('1.2.3-beta1', '1.2.3-beta1'),
  60. array('1.2.3rc1', '1.2.3-RC1'),
  61. array('1.2.3-rc1', '1.2.3-RC1'),
  62. array('1.2.3rc2', '1.2.3-RC2'),
  63. array('1.2.3-rc2', '1.2.3-RC2'),
  64. array('1.2.3rc.2', '1.2.3-RC.2'),
  65. array('1.2.3-rc.2', '1.2.3-RC.2'),
  66. array('1.2.3+0', '1.2.3-patch0'),
  67. array('1.2.3-0', '1.2.3-patch0'),
  68. array('1.2.3pre', '1.2.3-beta1'),
  69. array('1.2.3-pre', '1.2.3-beta1'),
  70. array('1.2.3dev', '1.2.3-dev'),
  71. array('1.2.3-dev', '1.2.3-dev'),
  72. array('1.2.3+build2012', '1.2.3-patch2012'),
  73. array('1.2.3-build2012', '1.2.3-patch2012'),
  74. array('1.2.3+build.2012', '1.2.3-patch.2012'),
  75. array('1.2.3-build.2012', '1.2.3-patch.2012'),
  76. array('latest', 'default || *'),
  77. array(null, '*'),
  78. array('', '*'),
  79. );
  80. }
  81. /**
  82. * @dataProvider getTestRanges
  83. */
  84. public function testRangeConverter($semver, $composer)
  85. {
  86. $this->assertEquals($composer, $this->converter->convertRange($semver));
  87. }
  88. public function getTestRanges()
  89. {
  90. return array(
  91. array('>1.2.3', '>1.2.3'),
  92. array('<1.2.3', '<1.2.3'),
  93. array('>=1.2.3', '>=1.2.3'),
  94. array('<=1.2.3', '<=1.2.3'),
  95. array('~1.2.3', '~1.2.3'),
  96. array('~1', '~1'),
  97. array('^1.2.3', '>=1.2.3,<2.0.0'),
  98. array('^1.2', '>=1.2.0,<2.0.0'),
  99. array('^1.x', '>=1.0.0,<2.0.0'),
  100. array('^1', '>=1.0.0,<2.0.0'),
  101. array('>1.2.3 <2.0', '>1.2.3,<2.0'),
  102. array('>1.2 <2.0', '>1.2,<2.0'),
  103. array('>1 <2', '>1,<2'),
  104. array('>=1.2.3 <2.0', '>=1.2.3,<2.0'),
  105. array('>=1.2 <2.0', '>=1.2,<2.0'),
  106. array('>=1 <2', '>=1,<2'),
  107. array('>=1.0 <1.1 || >=1.2', '>=1.0,<1.1|>=1.2'),
  108. array('< 1.2.3', '<1.2.3'),
  109. array('> 1.2.3', '>1.2.3'),
  110. array('<= 1.2.3', '<=1.2.3'),
  111. array('>= 1.2.3', '>=1.2.3'),
  112. array('~ 1.2.3', '~1.2.3'),
  113. array('~1.2.x', '~1.2.0'),
  114. array('~ 1.2', '~1.2'),
  115. array('~ 1', '~1'),
  116. array('^ 1.2.3', '>=1.2.3,<2.0.0'),
  117. array('1.2.3 - 2.3.4', '>=1.2.3,<=2.3.4'),
  118. array('>=0.10.x', '>=0.10.0'),
  119. array('>=0.10.*', '>=0.10.0'),
  120. array('<=0.10.x', '<=0.10.9999999'),
  121. array('<=0.10.*', '<=0.10.9999999'),
  122. array('=1.2.x', '1.2.x'),
  123. array('1.x.x', '1.x'),
  124. array('1.x.x.x', '1.x'),
  125. array('2.X.X.X', '2.x'),
  126. array('2.X.x.x', '2.x'),
  127. array('>=1.2.3 <2.0', '>=1.2.3,<2.0'),
  128. array('^1.2.3', '>=1.2.3,<2.0.0'),
  129. array('^0.2.3', '>=0.2.3,<0.3.0'),
  130. array('^0.0.3', '>=0.0.3,<0.0.4'),
  131. array('^1.2.3-beta.2', '>=1.2.3-beta.2,<2.0.0'),
  132. array('^0.0.3-beta', '>=0.0.3-beta1,<0.0.4'),
  133. array('^1.2.x', '>=1.2.0,<2.0.0'),
  134. array('^0.0.x', '>=0.0.0,<0.1.0'),
  135. array('^0.0', '>=0.0.0,<0.1.0'),
  136. array('^1.x', '>=1.0.0,<2.0.0'),
  137. array('^0.x', '>=0.0.0,<1.0.0'),
  138. array('~v1', '~1'),
  139. array('~v1-beta', '~1-beta1'),
  140. array('~v1.2', '~1.2'),
  141. array('~v1.2-beta', '~1.2-beta1'),
  142. array('~v1.2.3', '~1.2.3'),
  143. array('~v1.2.3-beta', '~1.2.3-beta1'),
  144. );
  145. }
  146. }