Completed
Push — master ( 1597db...37b3e5 )
by mw
16:02
created

testNewAnnotatedLanguageParserFunctionDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace SIL\Tests;
4
5
use SIL\ParserFunctionFactory;
6
use Title;
7
use Parser;
8
use ParserOptions;
9
10
/**
11
 * @covers \SIL\ParserFunctionFactory
12
 * @group semantic-interlanguage-links
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class ParserFunctionFactoryTest extends \PHPUnit_Framework_TestCase {
20
21
	private $parser;
22
23
	protected function setUp() {
24
		parent::setUp();
25
26
		$this->parser = new Parser();
27
		$this->parser->Options( new ParserOptions() );
28
		$this->parser->clearState();
29
	}
30
31
	public function testCanConstruct() {
32
33
		$this->assertInstanceOf(
34
			'\SIL\ParserFunctionFactory',
35
			new ParserFunctionFactory()
36
		);
37
	}
38
39
	public function testNewInterlanguageLinkParserFunctionDefinition() {
40
41
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
42
			->disableOriginalConstructor()
43
			->getMock();
44
45
		$pageContentLanguageOnTheFlyModifier = $this->getMockBuilder( '\SIL\PageContentLanguageOnTheFlyModifier' )
46
			->disableOriginalConstructor()
47
			->getMock();
48
49
		$this->parser->setTitle( Title::newFromText( __METHOD__ ) );
50
51
		$instance = new ParserFunctionFactory();
52
53
		list( $name, $definition, $flag ) = $instance->newInterlanguageLinkParserFunctionDefinition(
54
			$interlanguageLinksLookup,
55
			$pageContentLanguageOnTheFlyModifier
56
		);
57
58
		$this->assertEquals(
59
			'interlanguagelink',
60
			$name
61
		);
62
63
		$this->assertInstanceOf(
64
			'\Closure',
65
			$definition
66
		);
67
68
		$text = '';
69
70
		$this->assertNotEmpty(
71
			call_user_func_array( $definition, array( $this->parser, $text ) )
72
		);
73
	}
74
75
	public function testNewInterlanguageListParserFunctionDefinition() {
76
77
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
78
			->disableOriginalConstructor()
79
			->getMock();
80
81
		$this->parser->setTitle( Title::newFromText( __METHOD__ ) );
82
83
		$instance = new ParserFunctionFactory();
84
85
		list( $name, $definition, $flag ) = $instance->newInterlanguageListParserFunctionDefinition(
86
			$interlanguageLinksLookup
87
		);
88
89
		$this->assertEquals(
90
			'interlanguagelist',
91
			$name
92
		);
93
94
		$this->assertInstanceOf(
95
			'\Closure',
96
			$definition
97
		);
98
99
		$text = '';
100
101
		$this->assertNotEmpty(
102
			call_user_func_array( $definition, array( $this->parser, $text ) )
103
		);
104
	}
105
106
	public function testNewAnnotatedLanguageParserFunctionDefinition() {
107
108
		$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
109
			->disableOriginalConstructor()
110
			->getMock();
111
112
		$this->parser->setTitle( Title::newFromText( __METHOD__ ) );
113
114
		$instance = new ParserFunctionFactory();
115
116
		list( $name, $definition, $flag ) = $instance->newAnnotatedLanguageParserFunctionDefinition(
0 ignored issues
show
Unused Code introduced by
The assignment to $flag is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
117
			$interlanguageLinksLookup
118
		);
119
120
		$this->assertEquals(
121
			'annotatedlanguage',
122
			$name
123
		);
124
125
		$text = '';
126
127
		$this->assertEmpty(
128
			call_user_func_array( $definition, array( $this->parser, $text ) )
129
		);
130
	}
131
132
}
133