aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/App/AppStore/Version/VersionParserTest.php
blob: c461bf7c6cf21c24715d6b3d64a04de166c2a8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?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 function versionProvider() {
		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'),
			],
		];
	}

	/**
	 * @dataProvider versionProvider
	 *
	 * @param string $input
	 * @param Version $expected
	 */
	public function testGetVersion($input,
		Version $expected) {
		$this->assertEquals($expected, $this->versionParser->getVersion($input));
	}

	
	public function testGetVersionException() {
		$this->expectException(\Exception::class);
		$this->expectExceptionMessage('Version cannot be parsed: BogusVersion');

		$this->versionParser->getVersion('BogusVersion');
	}

	
	public function testGetVersionExceptionWithMultiple() {
		$this->expectException(\Exception::class);
		$this->expectExceptionMessage('Version cannot be parsed: >=8.2 <=9.1a');

		$this->versionParser->getVersion('>=8.2 <=9.1a');
	}
}