Completed
Push — renovate/major-react-monorepo ( 880c2b...a6f86c )
by
unknown
355:09 queued 345:32
created

is_version_update_required_provider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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