GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( e46154...4b4c9f )
by
unknown
33:31 queued 11s
created

tests/phpunit/Unit/LingoParserTest.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * This file is part of the MediaWiki extension Lingo.
4
 *
5
 * @copyright 2011 - 2018, Stephan Gambke
6
 * @license GPL-2.0-or-later
7
 *
8
 * The Lingo extension is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by the Free
10
 * Software Foundation; either version 2 of the License, or (at your option) any
11
 * later version.
12
 *
13
 * The Lingo extension is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
 * details.
17
 *
18
 * You should have received a copy of the GNU General Public License along
19
 * with this program. If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 * @author Stephan Gambke
22
 * @since 2.0
23
 * @file
24
 * @ingroup Lingo
25
 */
26
27
namespace Lingo\Tests\Unit;
28
29
use Lingo\LingoParser;
30
use PHPUnit\Framework\MockObject\MockObject;
0 ignored issues
show
The type PHPUnit\Framework\MockObject\MockObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
32
/**
33
 * @group extensions-lingo
34
 * @group extensions-lingo-unit
35
 * @group mediawiki-databaseless
36
 *
37
 * @coversDefaultClass \Lingo\LingoParser
38
 * @covers ::<private>
39
 * @covers ::<protected>
40
 *
41
 * @ingroup Lingo
42
 * @ingroup Test
43
 */
44
class LingoParserTest extends \PHPUnit\Framework\TestCase {
45
46
	private static $defaultTestConfig = [
47
		'mwParserExpectsGetOutput' => null,
48
		'mwParserExpectsGetTitle' => null,
49
		'mwTitleExpectsGetNamespace' => null,
50
		'mwOutputExpectsGetText' => null,
51
52
		'mwParserProperties' => [],
53
54
		'namespace' => 0,
55
		'text' => null,
56
57
		'wgexLingoUseNamespaces' => [],
58
		'wgexLingoBackend' => 'Lingo\\BasicBackend',
59
	];
60
61
	/**
62
	 * @covers ::__construct
63
	 */
64
	public function testCanConstruct() {
65
		$this->assertInstanceOf(
66
			'\Lingo\LingoParser',
67
			new \Lingo\LingoParser()
68
		);
69
	}
70
71
	/**
72
	 * This will NOT test the execution path in LingoParser::getInstance where the singleton is actually created as that
73
	 * path is executed during the initialisation of MW. It will test however that the singleton is of the correct class
74
	 * and that once created subsequent calls to LingoParser::getInstance will return the same object.
75
	 *
76
	 * @covers ::getInstance
77
	 */
78
	public function testGetInstance() {
79
		$singleton = LingoParser::getInstance();
80
81
		$this->assertInstanceOf(
82
			'\Lingo\LingoParser',
83
			$singleton
84
		);
85
86
		$this->assertEquals( $singleton, LingoParser::getInstance() );
87
	}
88
89
	/**
90
	 * Tests
91
	 *
92
	 *
93
	 * @covers ::parse
94
	 * @dataProvider parseProvider
95
	 */
96
	public function testParse( $config ) {
97
		// Setup
98
		$config += self::$defaultTestConfig;
99
100
		$mwParser = $this->getParserMock( $config );
101
		$backend = $this->getBackendMock();
102
103
		$parser = new LingoParser();
104
		$parser->setBackend( $backend );
105
106
		$GLOBALS[ 'wgLingoPageName' ] = 'SomePage';
107
		$GLOBALS[ 'wgexLingoUseNamespaces' ] = $config[ 'wgexLingoUseNamespaces' ];
108
109
		// Run
110
		$ret = $parser->parse( $mwParser );
111
112
		// Check
113
		$this->assertTrue( $ret );
114
115
		// Teardown
116
	}
117
118
	/**
119
	 * @return array
120
	 */
121
	public function parseProvider() {
122
		return [
123
			// trivial case where $wgParser being unset should at least not raise any exceptions
124
			[ [ 'mwParser' => null ] ],
125
126
			// Lingo parser does not start parsing (i.e. accesses parser output) when __NOGLOSSARY__ is set
127
			[ [
128
				'mwParserExpectsGetOutput' => $this->never(),
129
				'mwParserProperties' => [ 'mDoubleUnderscores' => [ 'noglossary' => true ] ],
130
			] ],
131
132
			// Lingo parser does not start parsing (i.e. accesses parser output) when parsed Page is unknown
133
			[ [
134
				'mwParserExpectsGetOutput' => $this->never(),
135
				'mwTitle' => null
136
			] ],
137
138
			// Lingo parser does not start parsing (i.e. accesses parser output) when parsed Page is in explicitly forbidden namespace
139
			[ [
140
				'mwParserExpectsGetOutput' => $this->never(),
141
				'namespace' => 100,
142
				'wgexLingoUseNamespaces' => [ 100 => false ],
143
			] ],
144
145
			// Lingo parser starts parsing (i.e. accesses parser output) when parsed Page is in explicitly allowed namespace
146
			[ [
147
				'mwParserExpectsGetOutput' => $this->once(),
148
				'namespace' => 100,
149
				'wgexLingoUseNamespaces' => [ 100 => true ],
150
			] ],
151
152
			// Lingo parser starts parsing (i.e. accesses parser output) when parsed Page is not in explicitly forbidden namespace
153
			[ [
154
				'mwParserExpectsGetOutput' => $this->once(),
155
				'namespace' => 100,
156
				'wgexLingoUseNamespaces' => [ 101 => false ],
157
			] ],
158
159
			// Not a real test. Just make sure that it does not break right away.
160
			[ [
161
				'text' => 'foo',
162
			] ],
163
164
		];
165
	}
166
167
	/**
168
	 * @return MockObject
169
	 */
170
	protected function getParserMock( $config = [] ) {
171
		if ( array_key_exists( 'mwParser', $config ) ) {
172
			return $config[ 'mwParser' ];
173
		}
174
175
		$mwTitle = $this->getTitleMock( $config );
176
177
		$mwParserOutput = $this->getMockBuilder( '\ParserOutput' )
178
			->disableOriginalConstructor()
179
			->getMock();
180
181
		$mwParser = $this->getMockBuilder( '\Parser' )
182
			->disableOriginalConstructor()
183
			->getMock();
184
185
		$mwParserOutput->expects( $config[ 'mwOutputExpectsGetText' ] ?: $this->any() )
186
			->method( 'getText' )
187
			->willReturn( $config[ 'text' ] );
188
189
		$mwParser->expects( $config[ 'mwParserExpectsGetTitle' ] ?: $this->any() )
190
			->method( 'getTitle' )
191
			->willReturn( $mwTitle );
192
193
		$mwParser->expects( $config[ 'mwParserExpectsGetOutput' ] ?: $this->any() )
194
			->method( 'getOutput' )
195
			->willReturn( $mwParserOutput );
196
197
		foreach ( $config[ 'mwParserProperties' ] as $propName => $propValue ) {
198
			$mwParser->$propName = $propValue;
199
		}
200
201
		return $mwParser;
202
	}
203
204
	/**
205
	 * @param $config
206
	 *
207
	 * @return MockObject
208
	 */
209
	protected function getTitleMock( $config ) {
210
		if ( array_key_exists( 'mwTitle', $config ) ) {
211
			return $config[ 'mwTitle' ];
212
		}
213
214
		$mwTitle = $this->getMockBuilder( '\Title' )
215
			->disableOriginalConstructor()
216
			->getMock();
217
218
		$mwTitle->expects( $config[ 'mwTitleExpectsGetNamespace' ] ?: $this->any() )
219
			->method( 'getNamespace' )
220
			->willReturn( $config[ 'namespace' ] );
221
222
		return $mwTitle;
223
	}
224
225
	/**
226
	 * @return MockObject
227
	 */
228
	protected function getBackendMock() {
229
		$backend = $this->getMockBuilder( 'Lingo\BasicBackend' )
230
			->disableOriginalConstructor()
231
			->setMethods( [
232
				'getLatestRevisionFromTitle',
233
				'getApprovedRevisionFromTitle',
234
				'getTitleFromText',
235
			] )
236
			->getMock();
237
238
		$lingoPageTitle = $this->getMockBuilder( 'Title' )
239
			->getMock();
240
		$lingoPageTitle->expects( $this->any() )
241
			->method( 'getInterwiki' )
242
			->willReturn( '' );
243
		$lingoPageTitle->expects( $this->any() )
244
			->method( 'getArticleID' )
245
			->willReturn( 'Foom' );
246
247
		$backend->expects( $this->any() )
248
			->method( 'getTitleFromText' )
249
			->willReturn( $lingoPageTitle );
250
251
		return $backend;
252
	}
253
254
}
255