Completed
Push — renovate/url-polyfill-1.x ( 01368d...f2aaf6 )
by
unknown
114:05 queued 106:27
created

test_is_version_update_required()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * The VersionSelectorTest class file.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Provides unit tests for the methods in the Version_Selector class.
12
 */
13
class VersionSelectorTest extends TestCase {
14
15
	/**
16
	 * This is called before each test.
17
	 */
18
	public function setUp() {
19
		$this->version_selector = new Version_Selector();
20
	}
21
22
	/**
23
	 * Tests is_version_update_required().
24
	 *
25
	 * @param String  $selected_version The currently selected package version.
26
	 * @param String  $compare_version The package version that is being compared to the
27
	 *                                 currently selected version to determine if the version
28
	 *                                 needs to be updated.
29
	 * @param Boolean $expected The expected Version_Selector::is_version_update_required() output.
30
	 *
31
	 * @covers Version_Selector::is_version_update_required
32
	 * @dataProvider is_version_update_required_provider
33
	 * @dataProvider is_version_update_required_without_dev_constant_provider
34
	 */
35
	public function test_is_version_update_required( $selected_version, $compare_version, $expected ) {
36
		$this->assertEquals( $expected, $this->version_selector->is_version_update_required( $selected_version, $compare_version ) );
37
	}
38
39
	/**
40
	 * Tests is_version_update_required() with the JETPACK_AUTOLOAD_DEV constant set to true.
41
	 *
42
	 * @param String  $selected_version The currently selected package version.
43
	 * @param String  $compare_version The package version that is being compared to the
44
	 *                                 currently selected version to determine if the version
45
	 *                                 needs to be updated.
46
	 * @param Boolean $expected The expected Version_Selector::is_version_update_required() output.
47
	 *
48
	 * @covers Version_Selector::is_version_update_required
49
	 * @dataProvider VersionSelectorTest::is_version_update_required_provider
50
	 * @dataProvider is_version_update_required_with_dev_constant_provider
51
	 * @runInSeparateProcess
52
	 * @preserveGlobalState disabled
53
	 */
54
	public function test_is_version_update_required_with_dev_constant( $selected_version, $compare_version, $expected ) {
55
		defined( 'JETPACK_AUTOLOAD_DEV' ) || define( 'JETPACK_AUTOLOAD_DEV', true );
56
		$this->assertEquals( $expected, $this->version_selector->is_version_update_required( $selected_version, $compare_version ) );
57
	}
58
59
	/**
60
	 * Data provider for the is_version_update_required() unit tests.
61
	 *
62
	 * This data provider covers inputs that are not affected by the JETPACK_AUTOLOAD_DEV
63
	 * constant.
64
	 *
65
	 * @return Array The test data.
66
	 */
67
	public static function is_version_update_required_provider() {
68
		return array(
69
			'selected greater than compare' => array( '2.0', '1.0', false ),
70
			'compare greater than selected' => array( '1.0', '2.0', true ),
71
			'selected null, compare stable' => array( null, '2.0', true ),
72
			'selected beta, compare stable' => array( '1.0-beta', '1.0', true ),
73
			'selected alpha, compare beta'  => array( '2.0-alpha', '2.0-beta', true ),
74
			'selected beta, compare less'   => array( '2.0-beta', '1.0', false ),
75
			'selected and compare dev'      => array( 'dev-test', 'dev-test2', false ),
76
			'selected null, compare dev'    => array( null, 'dev-test', true ),
77
		);
78
	}
79
80
	/**
81
	 * Data provider for the is_version_update_required() unit tests.
82
	 *
83
	 * This data provider covers inputs that are affected by the JETPACK_AUTOLOAD_DEV
84
	 * constant. The expected outputs in this provider are for environments where the
85
	 * JETPACK_AUTOLOAD_DEV constant is not set.
86
	 *
87
	 * @return Array The test data.
88
	 */
89
	public static function is_version_update_required_without_dev_constant_provider() {
90
		return array(
91
			'selected dev, compare stable' => array( 'dev-test', '1.0', true ),
92
			'selected stable, compare dev' => array( '1.0', 'dev-test', false ),
93
		);
94
	}
95
96
	/**
97
	 * Data provider for the is_version_update_required() unit tests.
98
	 *
99
	 * This data provider covers inputs that are affected by the JETPACK_AUTOLOAD_DEV
100
	 * constant. The expected outputs in this provider are for environments where the
101
	 * JETPACK_AUTOLOAD_DEV constant is set to 'true'.
102
	 *
103
	 * @return Array The test data.
104
	 */
105
	public function is_version_update_required_with_dev_constant_provider() {
106
		return array(
107
			'selected dev, compare stable' => array( 'dev-test', '1.0', false ),
108
			'selected stable, compare dev' => array( '1.0', 'dev-test', true ),
109
		);
110
	}
111
}
112