DistanceTest::parametersProvider()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Tests\Integration\ParserHooks;
6
7
use Maps\ParserHooks\DistanceFunction;
8
9
/**
10
 * @covers DistanceFunction
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class DistanceTest extends ParserHookTest {
16
17
	private $distances = [
18
		'42' => 42,
19
		'42m' => 42,
20
		'42 m' => 42,
21
		'42 km' => 42000,
22
		'4.2 km' => 4200,
23
		'4.2 m' => 4.2,
24
	];
25
26
	/**
27
	 * @see ParserHookTest::parametersProvider
28
	 */
29
	public function parametersProvider() {
30
		$paramLists = [];
31
32
		foreach ( array_keys( $this->distances ) as $distance ) {
33
			$paramLists[] = [ 'distance' => (string)$distance ];
34
		}
35
36
		return $this->arrayWrap( $paramLists );
37
	}
38
39
	/**
40
	 * @see ParserHookTest::processingProvider
41
	 */
42
	public function processingProvider() {
43
		$argLists = [];
44
45
		foreach ( $this->distances as $input => $output ) {
46
			$values = [
47
				'distance' => (string)$input,
48
			];
49
50
			$expected = [
51
				'distance' => $output,
52
			];
53
54
			$argLists[] = [ $values, $expected ];
55
		}
56
57
		$values = [
58
			'distance' => '42m',
59
			'unit' => 'km',
60
			'decimals' => '1',
61
		];
62
63
		$expected = [
64
			'distance' => 42,
65
			'unit' => 'km',
66
			'decimals' => 1,
67
		];
68
69
		$argLists[] = [ $values, $expected ];
70
71
		$values = [
72
			'distance' => '42m',
73
			'unit' => '~=[,,_,,]:3',
74
			'decimals' => 'foobar',
75
		];
76
77
		$expected = [
78
			'distance' => 42,
79
		];
80
81
		$argLists[] = [ $values, $expected ];
82
83
		return $argLists;
84
	}
85
86
	/**
87
	 * @see ParserHookTest::getInstance
88
	 */
89
	protected function getInstance() {
90
		return new \Maps\ParserHooks\DistanceFunction();
91
	}
92
93
}
94