Completed
Push — master ( cc71a9...8fd32c )
by Jeroen De
06:41
created

DistanceParserTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidInputs() 0 6 1
A validInputProvider() 0 12 1
A testGivenInvalidInput_exceptionIsThrown() 0 6 1
A invalidInputProvider() 0 14 1
1
<?php
2
3
namespace Maps\Tests\Integration\Parsers;
4
5
use Maps\Presentation\WikitextParsers\DistanceParser;
6
use PHPUnit\Framework\TestCase;
7
use PHPUnit4And6Compat;
8
use ValueParsers\ParseException;
9
10
/**
11
 * @covers \Maps\Presentation\WikitextParsers\DistanceParser
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class DistanceParserTest extends TestCase {
16
	use PHPUnit4And6Compat;
17
18
	/**
19
	 * @dataProvider validInputProvider
20
	 */
21
	public function testValidInputs( $input, $expected ) {
22
		$this->assertSame(
23
			$expected,
24
			( new DistanceParser() )->parse( $input )
25
		);
26
	}
27
28
	public function validInputProvider() {
29
		return [
30
			[ '1', 1.0 ],
31
			[ '1m', 1.0 ],
32
			[ '42 km', 42000.0 ],
33
			[ '4.2 km', 4200.0 ],
34
			[ '4.2 m', 4.2 ],
35
			[ '4.02 m', 4.02 ],
36
			[ '4.02 km', 4020.0 ],
37
			[ '0.001 km', 1.0 ],
38
		];
39
	}
40
41
	/**
42
	 * @dataProvider invalidInputProvider
43
	 */
44
	public function testGivenInvalidInput_exceptionIsThrown( $input ) {
45
		$parser = new DistanceParser();
46
47
		$this->expectException( ParseException::class );
48
		$parser->parse( $input );
49
	}
50
51
	public function invalidInputProvider() {
52
		return [
53
			[ '' ],
54
			[ 'kittens' ],
55
			[ '1 kittens' ],
56
			[ '-1m' ],
57
			[ 'foo m' ],
58
			[ '1m foo' ],
59
			[ 'foo 1m' ],
60
			[ 'm1' ],
61
			[ '4. m' ],
62
			[ '4.2.1 m' ],
63
		];
64
	}
65
66
}
67