Completed
Push — master ( 11fa91...0ac284 )
by Jeroen De
19:42
created

phpunit/Integration/I18nJsonFileIntegrityTest.php (1 issue)

super-globals are not used.

Coding Style Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SEQL\Tests\Integration;
4
5
use SMW\Tests\Utils\UtilityFactory;
6
7
/**
8
 * @group semantic-external-query-lookup
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
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']['SemanticExternalQueryLookup'];
40
41
		$bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location );
42
		$bulkFileProvider->searchByFileExtension( 'json' );
43
44
		foreach ( $bulkFileProvider->getFiles() as $file ) {
45
			$provider[] = array( $file );
46
		}
47
48
		return $provider;
49
	}
50
51
}
52