Completed
Push — update/phpunit-php-8 ( e34c58...05aa04 )
by
unknown
137:27 queued 129:12
created

UtilsTest::tear_down()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
	 * @after
22
	 */
23
	public function tear_down() {
24
		Constants::clear_constants();
25
	}
26
27
	/**
28
	 * Tests the Utils::jetpack_api_constant_filter() method.
29
	 *
30
	 * @covers Automattic\Jetpack\Connection\Utils::jetpack_api_constant_filter
31
	 * @dataProvider jetpack_api_constant_filter_data_provider
32
	 *
33
	 * @param mixed  $constant_value The constant value.
34
	 * @param string $constant_name The constant name.
35
	 * @param mixed  $expected_output The expected output of Utils::get_jetpack_api_constant.
36
	 */
37
	public function test_jetpack_api_constant_filter( $constant_value, $constant_name, $expected_output ) {
38
		$this->assertEquals( $expected_output, Utils::jetpack_api_constant_filter( $constant_value, $constant_name ) );
39
	}
40
41
	/**
42
	 * Data provider for test_jetpack_api_constant_filter.
43
	 *
44
	 * The test data arrays have the format:
45
	 *    'constant_value'  => The value that the constant will be set to. Null if the constant will not be set.
46
	 *    'constant_name'   => The name of the constant.
47
	 *    'expected_output' => The expected output of Utils::jetpack_api_constant_filter().
48
	 */
49
	public function jetpack_api_constant_filter_data_provider() {
50
		return array(
51
			'jetpack__api_base_without_constant'     =>
52
				array(
53
					'constant_value'  => null,
54
					'constant_name'   => 'JETPACK__API_BASE',
55
					'expected_output' => Utils::DEFAULT_JETPACK__API_BASE,
56
				),
57
			'jetpack__api_version_without_constant'  =>
58
				array(
59
					'constant_value'  => null,
60
					'constant_name'   => 'JETPACK__API_VERSION',
61
					'expected_output' => Utils::DEFAULT_JETPACK__API_VERSION,
62
				),
63
			'no_default_value_in_utils'              =>
64
				array(
65
					'constant_value'  => null,
66
					'constant_name'   => 'JETPACK__TEST',
67
					'expected_output' => null,
68
				),
69
			'jetpack__api_base_with_constant_set'    =>
70
				array(
71
					'constant_value'  => 'https://example.com/api/base.',
72
					'constant_name'   => 'JETPACK__API_BASE',
73
					'expected_output' => 'https://example.com/api/base.',
74
				),
75
			'jetpack__api_version_with_constant_set' =>
76
				array(
77
					'constant_value'  => 20,
78
					'constant_name'   => 'JETPACK__API_VERSION',
79
					'expected_output' => 20,
80
				),
81
		);
82
	}
83
}
84