Completed
Push — MediaWikiFileUrlFinderTest ( d58bee )
by Jeroen De
03:36
created

ParameterExtractorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 67
rs 10
c 0
b 0
f 0

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