DistanceParserTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 51
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
declare( strict_types = 1 );
4
5
namespace Maps\Tests\Integration\Parsers;
6
7
use Maps\WikitextParsers\DistanceParser;
8
use PHPUnit\Framework\TestCase;
9
use ValueParsers\ParseException;
10
11
/**
12
 * @covers \Maps\WikitextParsers\DistanceParser
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class DistanceParserTest extends TestCase {
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