VersionParserTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\App\AppStore\Version;
  7. use OC\App\AppStore\Version\Version;
  8. use OC\App\AppStore\Version\VersionParser;
  9. use Test\TestCase;
  10. class VersionParserTest extends TestCase {
  11. /** @var VersionParser */
  12. private $versionParser;
  13. protected function setUp(): void {
  14. parent::setUp();
  15. $this->versionParser = new VersionParser();
  16. }
  17. /**
  18. * @return array
  19. */
  20. public function versionProvider() {
  21. return [
  22. [
  23. '*',
  24. new Version('', ''),
  25. ],
  26. [
  27. '<=8.1.2',
  28. new Version('', '8.1.2'),
  29. ],
  30. [
  31. '<=9',
  32. new Version('', '9'),
  33. ],
  34. [
  35. '>=9.3.2',
  36. new Version('9.3.2', ''),
  37. ],
  38. [
  39. '>=8.1.2 <=9.3.2',
  40. new Version('8.1.2', '9.3.2'),
  41. ],
  42. [
  43. '>=8.2 <=9.1',
  44. new Version('8.2', '9.1'),
  45. ],
  46. [
  47. '>=9 <=11',
  48. new Version('9', '11'),
  49. ],
  50. ];
  51. }
  52. /**
  53. * @dataProvider versionProvider
  54. *
  55. * @param string $input
  56. * @param Version $expected
  57. */
  58. public function testGetVersion($input,
  59. Version $expected): void {
  60. $this->assertEquals($expected, $this->versionParser->getVersion($input));
  61. }
  62. public function testGetVersionException(): void {
  63. $this->expectException(\Exception::class);
  64. $this->expectExceptionMessage('Version cannot be parsed: BogusVersion');
  65. $this->versionParser->getVersion('BogusVersion');
  66. }
  67. public function testGetVersionExceptionWithMultiple(): void {
  68. $this->expectException(\Exception::class);
  69. $this->expectExceptionMessage('Version cannot be parsed: >=8.2 <=9.1a');
  70. $this->versionParser->getVersion('>=8.2 <=9.1a');
  71. }
  72. }