Passed
Pull Request — master (#136)
by None
04:09
created

PageBuilderTest::testGetHtml()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 8.8509
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SCI\Tests\Specials\CitableMetadata;
4
5
use SCI\Specials\CitableMetadata\PageBuilder;
6
7
/**
8
 * @covers \SCI\Specials\CitableMetadata\PageBuilder
9
 * @group semantic-cite
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class PageBuilderTest extends \PHPUnit_Framework_TestCase {
17
18
	private $htmlFormRenderer;
19
	private $hmlColumnListRenderer;
20
	private $citationResourceMatchFinder;
21
	private $httpResponseParserFactory;
22
23
	protected function setUp() : void {
24
25
		$this->htmlFormRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlFormRenderer' )
26
			->disableOriginalConstructor()
27
			->getMock();
28
29
		$this->hmlColumnListRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlColumnListRenderer' )
30
			->disableOriginalConstructor()
31
			->getMock();
32
33
		$this->citationResourceMatchFinder = $this->getMockBuilder( '\SCI\CitationResourceMatchFinder' )
34
			->disableOriginalConstructor()
35
			->getMock();
36
37
		$this->httpResponseParserFactory = $this->getMockBuilder( '\SCI\FilteredMetadata\HttpResponseParserFactory' )
38
			->disableOriginalConstructor()
39
			->getMock();
40
	}
41
42
	public function testCanConstruct() {
43
44
		$instance = new PageBuilder(
45
			$this->htmlFormRenderer,
46
			$this->hmlColumnListRenderer,
47
			$this->citationResourceMatchFinder,
48
			$this->httpResponseParserFactory
49
		);
50
51
		$this->assertInstanceOf(
52
			'\SCI\Specials\CitableMetadata\PageBuilder',
53
			$instance
54
		);
55
	}
56
57
	public function testGetRawResponse() {
58
59
		$responseParser = $this->getMockBuilder( '\Onoi\Remi\ResponseParser' )
60
			->disableOriginalConstructor()
61
			->getMockForAbstractClass();
62
63
		$responseParser->expects( $this->once() )
64
			->method( 'getRawResponse' )
65
			->with( $this->identicalTo( 42 ) );
66
67
		$this->httpResponseParserFactory->expects( $this->once() )
68
			->method( 'newResponseParserForType' )
69
			->with( $this->stringContains( 'foo') )
70
			->will( $this->returnValue( $responseParser ) );
71
72
		$instance = new PageBuilder(
73
			$this->htmlFormRenderer,
74
			$this->hmlColumnListRenderer,
75
			$this->citationResourceMatchFinder,
76
			$this->httpResponseParserFactory
77
		);
78
79
		$instance->getRawResponseFor( 'foo', 42 );
80
	}
81
82
	public function testGetHtml() {
83
84
		$bibliographicFilteredRecord = $this->getMockBuilder( '\SCI\FilteredMetadata\BibliographicFilteredRecord' )
85
			->disableOriginalConstructor()
86
			->getMock();
87
88
		$responseParser = $this->getMockBuilder( '\Onoi\Remi\ResponseParser' )
89
			->disableOriginalConstructor()
90
			->getMockForAbstractClass();
91
92
		$responseParser->expects( $this->once() )
93
			->method( 'doFilterResponseFor' )
94
			->with( $this->identicalTo( 42 ) );
95
96
		$responseParser->expects( $this->any() )
97
			->method( 'getMessages' )
98
			->will( $this->returnValue( [] ) );
99
100
		$responseParser->expects( $this->atLeastOnce() )
101
			->method( 'getFilteredRecord' )
102
			->will( $this->returnValue( $bibliographicFilteredRecord ) );
103
104
		$message = $this->getMockBuilder( '\Message' )
105
			->disableOriginalConstructor()
106
			->getMock();
107
108
		$messageBuilder = $this->getMockBuilder( '\SMW\MediaWiki\MessageBuilder' )
109
			->disableOriginalConstructor()
110
			->getMock();
111
112
		$messageBuilder->expects( $this->any() )
113
			->method( 'getMessage' )
114
			->will( $this->returnValue( $message ) );
115
116
		$htmlFormRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlFormRenderer' )
117
			->disableOriginalConstructor()
118
			->setMethods( [ 'getMessageBuilder', 'getForm' ] )
119
			->getMock();
120
121
		$htmlFormRenderer->expects( $this->atLeastOnce() )
122
			->method( 'getMessageBuilder' )
123
			->will( $this->returnValue( $messageBuilder ) );
124
125
		$this->citationResourceMatchFinder->expects( $this->atLeastOnce() )
126
			->method( 'findMatchForResourceIdentifierTypeToValue' )
127
			->will( $this->returnValue( [] ) );
128
129
		$this->httpResponseParserFactory->expects( $this->once() )
130
			->method( 'newResponseParserForType' )
131
			->with( $this->stringContains( 'foo') )
132
			->will( $this->returnValue( $responseParser ) );
133
134
		$instance =	new PageBuilder(
135
			$htmlFormRenderer,
136
			$this->hmlColumnListRenderer,
137
			$this->citationResourceMatchFinder,
138
			$this->httpResponseParserFactory
139
		);
140
141
		$instance->getHtmlFor( 'foo', 42 );
142
	}
143
144
}
145