Nessuna descrizione

VersionConstraintParserTest.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /*
  3. * This file is part of PharIo\Version.
  4. *
  5. * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
  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 PharIo\Version;
  11. use PHPUnit\Framework\TestCase;
  12. /**
  13. * @covers \PharIo\Version\VersionConstraintParser
  14. */
  15. class VersionConstraintParserTest extends TestCase {
  16. /**
  17. * @dataProvider versionStringProvider
  18. *
  19. * @param string $versionString
  20. * @param VersionConstraint $expectedConstraint
  21. */
  22. public function testReturnsExpectedConstraint($versionString, VersionConstraint $expectedConstraint) {
  23. $parser = new VersionConstraintParser;
  24. $this->assertEquals($expectedConstraint, $parser->parse($versionString));
  25. }
  26. /**
  27. * @dataProvider unsupportedVersionStringProvider
  28. *
  29. * @param string $versionString
  30. */
  31. public function testThrowsExceptionIfVersionStringIsNotSupported($versionString) {
  32. $parser = new VersionConstraintParser;
  33. $this->expectException(UnsupportedVersionConstraintException::class);
  34. $parser->parse($versionString);
  35. }
  36. /**
  37. * @return array
  38. */
  39. public function versionStringProvider() {
  40. return [
  41. ['1.0.2', new ExactVersionConstraint('1.0.2')],
  42. [
  43. '~4.6',
  44. new AndVersionConstraintGroup(
  45. '~4.6',
  46. [
  47. new GreaterThanOrEqualToVersionConstraint('~4.6', new Version('4.6')),
  48. new SpecificMajorVersionConstraint('~4.6', 4)
  49. ]
  50. )
  51. ],
  52. [
  53. '~4.6.2',
  54. new AndVersionConstraintGroup(
  55. '~4.6.2',
  56. [
  57. new GreaterThanOrEqualToVersionConstraint('~4.6.2', new Version('4.6.2')),
  58. new SpecificMajorAndMinorVersionConstraint('~4.6.2', 4, 6)
  59. ]
  60. )
  61. ],
  62. [
  63. '^2.6.1',
  64. new AndVersionConstraintGroup(
  65. '^2.6.1',
  66. [
  67. new GreaterThanOrEqualToVersionConstraint('^2.6.1', new Version('2.6.1')),
  68. new SpecificMajorVersionConstraint('^2.6.1', 2)
  69. ]
  70. )
  71. ],
  72. ['5.1.*', new SpecificMajorAndMinorVersionConstraint('5.1.*', 5, 1)],
  73. ['5.*', new SpecificMajorVersionConstraint('5.*', 5)],
  74. ['*', new AnyVersionConstraint()],
  75. [
  76. '1.0.2 || 1.0.5',
  77. new OrVersionConstraintGroup(
  78. '1.0.2 || 1.0.5',
  79. [
  80. new ExactVersionConstraint('1.0.2'),
  81. new ExactVersionConstraint('1.0.5')
  82. ]
  83. )
  84. ],
  85. [
  86. '^5.6 || ^7.0',
  87. new OrVersionConstraintGroup(
  88. '^5.6 || ^7.0',
  89. [
  90. new AndVersionConstraintGroup(
  91. '^5.6', [
  92. new GreaterThanOrEqualToVersionConstraint('^5.6', new Version('5.6')),
  93. new SpecificMajorVersionConstraint('^5.6', 5)
  94. ]
  95. ),
  96. new AndVersionConstraintGroup(
  97. '^7.0', [
  98. new GreaterThanOrEqualToVersionConstraint('^7.0', new Version('7.0')),
  99. new SpecificMajorVersionConstraint('^7.0', 7)
  100. ]
  101. )
  102. ]
  103. )
  104. ],
  105. ['7.0.28-1', new ExactVersionConstraint('7.0.28-1')],
  106. [
  107. '^3.0.0-alpha1',
  108. new AndVersionConstraintGroup(
  109. '^3.0.0-alpha1',
  110. [
  111. new GreaterThanOrEqualToVersionConstraint('^3.0.0-alpha1', new Version('3.0.0-alpha1')),
  112. new SpecificMajorVersionConstraint('^3.0.0-alpha1', 3)
  113. ]
  114. )
  115. ],
  116. [
  117. '^3.0.0-alpha.1',
  118. new AndVersionConstraintGroup(
  119. '^3.0.0-alpha.1',
  120. [
  121. new GreaterThanOrEqualToVersionConstraint('^3.0.0-alpha.1', new Version('3.0.0-alpha.1')),
  122. new SpecificMajorVersionConstraint('^3.0.0-alpha.1', 3)
  123. ]
  124. )
  125. ]
  126. ];
  127. }
  128. public function unsupportedVersionStringProvider() {
  129. return [
  130. ['foo'],
  131. ['+1.0.2'],
  132. ['>=2.0'],
  133. ['^5.6 || >= 7.0'],
  134. ['2.0 || foo']
  135. ];
  136. }
  137. }