Completed
Push — oldjunk ( 6d7aaf...37c282 )
by Jeroen De
02:36
created

ParameterExtractorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenNoParameters_nullIsReturned() 0 3 1
A testGivenWhenPrimaryNameIsPresent_itsValueIsReturned() 0 9 1
A testGivenAliasIsPresent_itsValueIsReturned() 0 9 1
A testWhenAliasAndPrimaryArePresent_thePrimariesValueIsReturned() 0 9 1
A testValueIsTrimmed() 0 9 1
A testWhenUpperCaseIsUsedInTheName_itIsStillFound() 0 9 1
1
<?php
2
3
use Maps\ParameterExtractor;
4
use PHPUnit\Framework\TestCase;
5
6
/**
7
 * @covers \Maps\ParameterExtractor
8
 *
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class ParameterExtractorTest extends TestCase {
13
14
	public function testGivenNoParameters_nullIsReturned() {
15
		$this->assertNull( ( new ParameterExtractor() )->extract( [ 'name' ], [] ) );
16
	}
17
18
	public function testGivenWhenPrimaryNameIsPresent_itsValueIsReturned() {
19
		$this->assertSame(
20
			'value',
21
			( new ParameterExtractor() )->extract(
22
				[ 'name' ],
23
				[ 'foo' => 'bar', 'name' => 'value', 'baz' => 'bah' ]
24
			)
25
		);
26
	}
27
28
	public function testGivenAliasIsPresent_itsValueIsReturned() {
29
		$this->assertSame(
30
			'value',
31
			( new ParameterExtractor() )->extract(
32
				[ 'name', 'secondary', 'alias' ],
33
				[ 'foo' => 'bar', 'alias' => 'value', 'baz' => 'bah' ]
34
			)
35
		);
36
	}
37
38
	public function testWhenAliasAndPrimaryArePresent_thePrimariesValueIsReturned() {
39
		$this->assertSame(
40
			'value',
41
			( new ParameterExtractor() )->extract(
42
				[ 'name', 'secondary', 'alias' ],
43
				[ 'foo' => 'bar', 'alias' => 'wrong', 'name' => 'value' ]
44
			)
45
		);
46
	}
47
48
	public function testValueIsTrimmed() {
49
		$this->assertSame(
50
			'value',
51
			( new ParameterExtractor() )->extract(
52
				[ 'name' ],
53
				[ 'name' => "  value\t  " ]
54
			)
55
		);
56
	}
57
58
	public function testWhenUpperCaseIsUsedInTheName_itIsStillFound() {
59
		$this->assertSame(
60
			'value',
61
			( new ParameterExtractor() )->extract(
62
				[ 'name' ],
63
				[ 'nAmE' => 'value' ]
64
			)
65
		);
66
	}
67
68
}
69