Completed
Push — dvtest ( a10768 )
by Jeroen De
05:04
created

testGivenInvalidInput_exceptionIsThrown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 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
	/**
16
	 * @dataProvider validInputProvider
17
	 */
18
	public function testValidInputs( $input, $expected ) {
19
		$this->assertSame(
20
			$expected,
21
			( new DistanceParser() )->parse( $input )
22
		);
23
	}
24
25
	public function validInputProvider() {
26
		return [
27
			[ '1', 1 ],
28
			[ '1m', 1 ],
29
			[ '42 km', 42000 ],
30
			[ '4.2 km', 4200 ],
31
			[ '4.2 m', 4.2 ],
32
			[ '4.02 m', 4.02 ],
33
			[ '4.02 km', 4020 ],
34
			[ '0.001 km', 1 ],
35
		];
36
	}
37
38
	/**
39
	 * @dataProvider invalidInputProvider
40
	 */
41
	public function testGivenInvalidInput_exceptionIsThrown( $input ) {
42
		$parser = new DistanceParser();
43
44
		$this->setExpectedException( ParseException::class );
45
		$parser->parse( $input );
46
	}
47
48
	public function invalidInputProvider() {
49
		return [
50
			[ '' ],
51
			[ 'kittens' ],
52
			[ '1 kittens' ],
53
			[ '-1m' ],
54
			[ 'foo m' ],
55
			[ '1m foo' ],
56
			[ 'foo 1m' ],
57
			[ 'm1' ],
58
			[ '4. m' ],
59
			[ '4.2.1 m' ],
60
		];
61
	}
62
63
}
64