aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/App/AppStore/Version/VersionParserTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/App/AppStore/Version/VersionParserTest.php')
-rw-r--r--tests/lib/App/AppStore/Version/VersionParserTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/lib/App/AppStore/Version/VersionParserTest.php b/tests/lib/App/AppStore/Version/VersionParserTest.php
new file mode 100644
index 00000000000..3ccc68bc076
--- /dev/null
+++ b/tests/lib/App/AppStore/Version/VersionParserTest.php
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\App\AppStore\Version;
+
+use OC\App\AppStore\Version\Version;
+use OC\App\AppStore\Version\VersionParser;
+use Test\TestCase;
+
+class VersionParserTest extends TestCase {
+ /** @var VersionParser */
+ private $versionParser;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->versionParser = new VersionParser();
+ }
+
+ /**
+ * @return array
+ */
+ public static function versionProvider(): array {
+ return [
+ [
+ '*',
+ new Version('', ''),
+ ],
+ [
+ '<=8.1.2',
+ new Version('', '8.1.2'),
+ ],
+ [
+ '<=9',
+ new Version('', '9'),
+ ],
+ [
+ '>=9.3.2',
+ new Version('9.3.2', ''),
+ ],
+ [
+ '>=8.1.2 <=9.3.2',
+ new Version('8.1.2', '9.3.2'),
+ ],
+ [
+ '>=8.2 <=9.1',
+ new Version('8.2', '9.1'),
+ ],
+ [
+ '>=9 <=11',
+ new Version('9', '11'),
+ ],
+ ];
+ }
+
+ /**
+ *
+ * @param string $input
+ * @param Version $expected
+ */
+ #[\PHPUnit\Framework\Attributes\DataProvider('versionProvider')]
+ public function testGetVersion($input,
+ Version $expected): void {
+ $this->assertEquals($expected, $this->versionParser->getVersion($input));
+ }
+
+
+ public function testGetVersionException(): void {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Version cannot be parsed: BogusVersion');
+
+ $this->versionParser->getVersion('BogusVersion');
+ }
+
+
+ public function testGetVersionExceptionWithMultiple(): void {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Version cannot be parsed: >=8.2 <=9.1a');
+
+ $this->versionParser->getVersion('>=8.2 <=9.1a');
+ }
+}