Completed
Push — MediaWikiFileUrlFinderTest ( d58bee...394f02 )
by Jeroen De
08:48
created

DistanceTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 79
rs 10
c 0
b 0
f 0

3 Methods

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