I18nJsonFileIntegrityTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testI18NJsonDecodeEncode() 0 14 1
A i18nFileProvider() 0 16 3
1
<?php
2
3
namespace SMW\Scribunto\Tests\Integration;
4
5
use SMW\Tests\Utils\UtilityFactory;
6
7
/**
8
 * @group semantic-notifications
9
 * @group medium
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class I18nJsonFileIntegrityTest extends \PHPUnit_Framework_TestCase {
17
18
	/**
19
	 * @dataProvider i18nFileProvider
20
	 */
21
	public function testI18NJsonDecodeEncode( $file ) {
22
23
		$jsonFileReader = UtilityFactory::getInstance()->newJsonFileReader( $file );
24
25
		$this->assertInternalType(
26
			'integer',
27
			$jsonFileReader->getModificationTime()
28
		);
29
30
		$this->assertInternalType(
31
			'array',
32
			$jsonFileReader->read()
33
		);
34
	}
35
36
	public function i18nFileProvider() {
0 ignored issues
show
Coding Style introduced by
i18nFileProvider uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
37
38
		$provider = array();
39
		$location = $GLOBALS['wgMessagesDirs']['SemanticNotifications'];
40
41
		$location = is_array( $location ) ? end( $location ) : $location;
42
43
		$bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location );
44
		$bulkFileProvider->searchByFileExtension( 'json' );
45
46
		foreach ( $bulkFileProvider->getFiles() as $file ) {
47
			$provider[] = array( $file );
48
		}
49
50
		return $provider;
51
	}
52
53
}
54