LibraryFactoryTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 39 1
A testCanConstruct() 0 7 1
A testCanConstructQueryResult() 0 11 1
A testCanConstructParserParameterProcessor() 0 11 1
A testCanConstructSetParserFunction() 0 11 1
A testCanConstructSubobjectParserFunction() 0 11 1
A testCanConstructLuaAskResultProcessor() 0 15 1
1
<?php
2
3
namespace SMW\Scribunto\Tests;
4
5
use SMW\Scribunto\LibraryFactory;
6
7
/**
8
 * @covers \SMW\Scribunto\LibraryFactory
9
 * @group semantic-scribunto
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class LibraryFactoryTest extends \PHPUnit_Framework_TestCase {
17
18
	private $store;
19
	private $parser;
20
21
	protected function setUp() {
22
23
		$language = $this->getMockBuilder( '\Language' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$queryResult = $this->getMockBuilder( '\SMWQueryResult' )
28
			->disableOriginalConstructor()
29
			->getMock();
30
31
		$this->store = $this->getMockBuilder( '\SMW\Store' )
32
			->disableOriginalConstructor()
33
			->getMockForAbstractClass();
34
35
		$this->store->expects( $this->any() )
36
			->method( 'getQueryResult' )
37
			->will( $this->returnValue( $queryResult ) );
38
39
		$this->parser = $this->getMockBuilder( '\Parser' )
40
			->disableOriginalConstructor()
41
			->getMock();
42
43
		$mStripState = $this->getMockBuilder( '\StripState' )
44
			->disableOriginalConstructor()
45
			->getMock();
46
		$this->parser->mStripState = $mStripState;
47
48
		$this->parser->expects( $this->any() )
49
			->method( 'getTitle' )
50
			->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) );
51
52
		$this->parser->expects( $this->any() )
53
			->method( 'getOutput' )
54
			->will( $this->returnValue( new \ParserOutput() ) );
55
56
		$this->parser->expects( $this->any() )
57
			->method( 'getTargetLanguage' )
58
			->will( $this->returnValue( $language ) );
59
	}
60
61
	public function testCanConstruct() {
62
63
		$this->assertInstanceOf(
64
			'\SMW\Scribunto\LibraryFactory',
65
			new LibraryFactory( $this->store )
66
		);
67
	}
68
69
	public function testCanConstructQueryResult() {
70
71
		$instance = new LibraryFactory(
72
			$this->store
73
		);
74
75
		$this->assertInstanceOf(
76
			'\SMWQueryResult',
77
			$instance->newQueryResultFrom( [ '[[Foo::Bar]]' ] )
78
		);
79
	}
80
81
	public function testCanConstructParserParameterProcessor() {
82
83
		$instance = new LibraryFactory(
84
			$this->store
85
		);
86
87
		$this->assertInstanceOf(
88
			'\SMW\ParserParameterProcessor',
89
			$instance->newParserParameterProcessorFrom( [ '' ] )
90
		);
91
	}
92
93
	public function testCanConstructSetParserFunction() {
94
95
		$instance = new LibraryFactory(
96
			$this->store
97
		);
98
99
		$this->assertInstanceOf(
100
			'\SMW\ParserFunctions\SetParserFunction',
101
			$instance->newSetParserFunction( $this->parser )
102
		);
103
	}
104
105
	public function testCanConstructSubobjectParserFunction() {
106
107
		$instance = new LibraryFactory(
108
			$this->store
109
		);
110
111
		$this->assertInstanceOf(
112
			'\SMW\ParserFunctions\SubobjectParserFunction',
113
			$instance->newSubobjectParserFunction( $this->parser )
114
		);
115
	}
116
117
	public function testCanConstructLuaAskResultProcessor() {
118
119
		$queryResult = $this->getMockBuilder( '\SMWQueryResult' )
120
			->disableOriginalConstructor()
121
			->getMock();
122
123
		$instance = new LibraryFactory(
124
			$this->store
125
		);
126
127
		$this->assertInstanceOf(
128
			'\SMW\Scribunto\LuaAskResultProcessor',
129
			$instance->newLuaAskResultProcessor( $queryResult )
130
		);
131
	}
132
133
}
134