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