Completed
Push — merge-sm ( 44b830...c70fa4 )
by Jeroen De
10:03 queued 07:12
created

DistanceParserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

5 Methods

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