Completed
Push — tmp/not-master ( 0b734a )
by
unknown
115:59 queued 109:41
created

UtilsTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A test_jetpack_api_constant_filter() 0 3 1
A jetpack_api_constant_filter_data_provider() 0 34 1
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * The UtilsTest class file.
4
 *
5
 * @package automattic/jetpack-connection
6
 */
7
8
namespace Automattic\Jetpack\Connection;
9
10
use Automattic\Jetpack\Constants;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * Provides unit tests for the methods in the Utils class.
15
 */
16
class UtilsTest extends TestCase {
17
18
	/**
19
	 * This method is called after each test.
20
	 */
21
	public function tearDown() {
22
		Constants::clear_constants();
23
	}
24
25
26
	/**
27
	 * Tests the Utils::jetpack_api_constant_filter() method.
28
	 *
29
	 * @covers Automattic\Jetpack\Connection\Utils::jetpack_api_constant_filter
30
	 * @dataProvider jetpack_api_constant_filter_data_provider
31
	 *
32
	 * @param mixed  $constant_value The constant value.
33
	 * @param string $constant_name The constant name.
34
	 * @param mixed  $expected_output The expected output of Utils::get_jetpack_api_constant.
35
	 */
36
	public function test_jetpack_api_constant_filter( $constant_value, $constant_name, $expected_output ) {
37
		$this->assertEquals( $expected_output, Utils::jetpack_api_constant_filter( $constant_value, $constant_name ) );
38
	}
39
40
	/**
41
	 * Data provider for test_jetpack_api_constant_filter.
42
	 *
43
	 * The test data arrays have the format:
44
	 *    'constant_value'  => The value that the constant will be set to. Null if the constant will not be set.
45
	 *    'constant_name'   => The name of the constant.
46
	 *    'expected_output' => The expected output of Utils::jetpack_api_constant_filter().
47
	 */
48
	public function jetpack_api_constant_filter_data_provider() {
49
		return array(
50
			'jetpack__api_base_without_constant'     =>
51
				array(
52
					'constant_value'  => null,
53
					'constant_name'   => 'JETPACK__API_BASE',
54
					'expected_output' => Utils::DEFAULT_JETPACK__API_BASE,
55
				),
56
			'jetpack__api_version_without_constant'  =>
57
				array(
58
					'constant_value'  => null,
59
					'constant_name'   => 'JETPACK__API_VERSION',
60
					'expected_output' => Utils::DEFAULT_JETPACK__API_VERSION,
61
				),
62
			'no_default_value_in_utils'              =>
63
				array(
64
					'constant_value'  => null,
65
					'constant_name'   => 'JETPACK__TEST',
66
					'expected_output' => null,
67
				),
68
			'jetpack__api_base_with_constant_set'    =>
69
				array(
70
					'constant_value'  => 'https://example.com/api/base.',
71
					'constant_name'   => 'JETPACK__API_BASE',
72
					'expected_output' => 'https://example.com/api/base.',
73
				),
74
			'jetpack__api_version_with_constant_set' =>
75
				array(
76
					'constant_value'  => 20,
77
					'constant_name'   => 'JETPACK__API_VERSION',
78
					'expected_output' => 20,
79
				),
80
		);
81
	}
82
}
83