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
|
|
|
|