Passed
Branch master (631cc3)
by Stephan
33:03
created

LingoI18NTest::testMagicWordsLoaded()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 27
rs 8.8571
1
<?php
2
/**
3
 * This file is part of the MediaWiki extension Lingo.
4
 *
5
 * @copyright 2011 - 2016, Stephan Gambke
6
 * @license   GNU General Public License, version 2 (or any later version)
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
/**
30
 * @group extensions-lingo
31
 * @group extensions-lingo-unit
32
 * @group mediawiki-databaseless
33
 *
34
 * @ingroup Lingo
35
 * @ingroup Test
36
 */
37
class LingoI18NTest extends \PHPUnit\Framework\TestCase {
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase 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...
38
39
	public function testJsonSchemaValidatorExists(){
40
		$this->assertTrue( class_exists( '\JsonSchema\Validator' ) );
41
		$this->assertTrue( method_exists('\JsonSchema\Validator', 'check' ) );
42
	}
43
44
	public function testMagicWordsLoaded() {
45
46
		// load magic words
47
		require __DIR__ . '/../../../src/Lingo.i18n.magic.php';
48
49
		// assert $magicWords was created
50
		$defined_vars = get_defined_vars();
51
		$this->assertArrayHasKey( 'magicWords', $defined_vars );
52
53
		// validate structure
54
55
		$data = json_decode( json_encode( $defined_vars[ 'magicWords' ] ) );
56
57
		$validator = new \JsonSchema\Validator();
58
		$validator->check( $data, (object) array( '$ref' =>
59
			'file://' . realpath( __DIR__ . '/../Fixture/magicWordsSchema.json' ) ) );
60
61
		// format error message
62
		$errors = implode( '', array_map(
63
			function ( $error ) {
64
				return "* [{$error[ 'property' ]}] {$error[ 'message' ]}\n";
65
			},
66
			$validator->getErrors()
67
		) );
68
69
		// assert structure is valid
70
		$this->assertTrue( $validator->isValid(), "JSON does not validate. Violations:\n" . $errors );
71
	}
72
}
73