SubPageCountTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSubPageCountHook() 0 10 1
A newSubPageCount() 0 12 1
A getCountResult() 0 24 1
1
<?php
2
3
namespace Tests\Unit\SubPageList\Counter;
4
5
use ParamProcessor\ProcessedParam;
6
use ParamProcessor\ProcessingResult;
7
use PHPUnit\Framework\TestCase;
8
use SubPageList\Counter\SubPageCount;
9
use SubPageList\TitleFactory;
10
11
/**
12
 * @covers \SubPageList\Counter\SubPageCount
13
 *
14
 * @group SubPageList
15
 *
16
 * @licence GNU GPL v2+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class SubPageCountTest extends TestCase {
20
21
	public function testSubPageCountHook() {
22
		$titleText = 'FooBarPage';
23
		$numberOfSubPages = 42;
24
25
		$subPageCount = $this->newSubPageCount( $titleText, $numberOfSubPages );
26
		$countResult = $this->getCountResult( $subPageCount, $titleText );
27
28
		$this->assertInternalType( 'string', $countResult );
29
		$this->assertEquals( (string)$numberOfSubPages . '.0', $countResult );
30
	}
31
32
	private function newSubPageCount( $titleText, $numberOfSubPages ) {
33
		$titleFactory = new TitleFactory();
34
35
		$counter = $this->createMock( 'SubPageList\Counter\SubPageCounter' );
36
37
		$counter->expects( $this->once() )
38
			->method( 'countSubPages' )
39
			->with( $titleFactory->newFromText( $titleText ) )
40
			->will( $this->returnValue( $numberOfSubPages ) );
41
42
		return new SubPageCount( $counter, $titleFactory );
43
	}
44
45
	private function getCountResult( SubPageCount $subPageCount, $titleText ) {
46
		$language = $this->createMock( 'Language' );
47
48
		$language->expects( $this->once() )
49
			->method( 'formatNum' )
50
			->will( $this->returnCallback( function( $number ) {
51
				return (string)$number . '.0';
52
			} ) );
53
54
		$parser = $this->createMock( 'Parser' );
55
56
		$parser->expects( $this->once() )
57
			->method( 'getTargetLanguage' )
58
			->will( $this->returnValue( $language ) );
59
60
		$processingResult = new ProcessingResult(
61
			[
62
				'page' => new ProcessedParam( 'page', $titleText, false )
63
			],
64
			[]
65
		);
66
67
		return $subPageCount->handle( $parser, $processingResult );
68
	}
69
70
}
71