VersionParserTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\App\AppStore\Version;
  22. use OC\App\AppStore\Version\Version;
  23. use OC\App\AppStore\Version\VersionParser;
  24. use Test\TestCase;
  25. class VersionParserTest extends TestCase {
  26. /** @var VersionParser */
  27. private $versionParser;
  28. public function setUp() {
  29. parent::setUp();
  30. $this->versionParser = new VersionParser();
  31. }
  32. /**
  33. * @return array
  34. */
  35. public function versionProvider() {
  36. return [
  37. [
  38. '*',
  39. new Version('', ''),
  40. ],
  41. [
  42. '<=8.1.2',
  43. new Version('', '8.1.2'),
  44. ],
  45. [
  46. '<=9',
  47. new Version('', '9'),
  48. ],
  49. [
  50. '>=9.3.2',
  51. new Version('9.3.2', ''),
  52. ],
  53. [
  54. '>=8.1.2 <=9.3.2',
  55. new Version('8.1.2', '9.3.2'),
  56. ],
  57. [
  58. '>=8.2 <=9.1',
  59. new Version('8.2', '9.1'),
  60. ],
  61. [
  62. '>=9 <=11',
  63. new Version('9', '11'),
  64. ],
  65. ];
  66. }
  67. /**
  68. * @dataProvider versionProvider
  69. *
  70. * @param string $input
  71. * @param Version $expected
  72. */
  73. public function testGetVersion($input,
  74. Version $expected) {
  75. $this->assertEquals($expected, $this->versionParser->getVersion($input));
  76. }
  77. /**
  78. * @expectedException \Exception
  79. * @expectedExceptionMessage Version cannot be parsed: BogusVersion
  80. */
  81. public function testGetVersionException() {
  82. $this->versionParser->getVersion('BogusVersion');
  83. }
  84. /**
  85. * @expectedException \Exception
  86. * @expectedExceptionMessage Version cannot be parsed: >=8.2 <=9.1a
  87. */
  88. public function testGetVersionExceptionWithMultiple() {
  89. $this->versionParser->getVersion('>=8.2 <=9.1a');
  90. }
  91. }