wiki.techinc.nl/tests/phpunit/unit/includes/Settings/Source/FileSourceTest.php
Reedy 5f2584b648 tests: Rename fixtures/bad.json
Bug: T306524
Change-Id: I3b97c041bf2e1171bd6e31774de12ae1d73f95a4
2022-04-20 15:17:36 +01:00

70 lines
1.8 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Settings\Source;
use MediaWiki\Settings\SettingsBuilderException;
use MediaWiki\Settings\Source\FileSource;
use MediaWiki\Settings\Source\Format\JsonFormat;
use PHPUnit\Framework\TestCase;
/**
* @covers \MediaWiki\Settings\Source\FileSource
*/
class FileSourceTest extends TestCase {
public function testAllowsStaleLoad() {
$source = new FileSource( __DIR__ . 'foo.json' );
$this->assertFalse( $source->allowsStaleLoad() );
}
public function testLoad() {
$source = new FileSource( __DIR__ . '/fixtures/settings.json' );
$settings = $source->load();
$this->assertSame(
[ 'config' => [ 'MySetting' => 'BlaBla' ] ],
$source->load()
);
}
public function testLoadFormat() {
$source = new FileSource( __DIR__ . '/fixtures/settings.json', new JsonFormat() );
$settings = $source->load();
$this->assertSame(
[ 'config' => [ 'MySetting' => 'BlaBla' ] ],
$source->load()
);
}
public function testLoadBadFormat() {
$source = new FileSource( __DIR__ . '/fixtures/bad.txt', new JsonFormat() );
$this->expectException( SettingsBuilderException::class );
$settings = $source->load();
}
public function testLoadDirectory() {
$source = new FileSource( __DIR__ . '/fixtures/dir.json' );
$this->expectException( SettingsBuilderException::class );
$settings = $source->load();
}
public function testLoadNoSuitableFormats() {
$source = new FileSource( __DIR__ . '/fixtures/settings.toml', new JsonFormat() );
$this->expectException( SettingsBuilderException::class );
$settings = $source->load();
}
public function testGetHashKey() {
$source = new FileSource( __DIR__ . '/fixtures/settings.json' );
// We can't reliably mock the filesystem stat so simply ensure the
// method returns and is non-zero in length
$this->assertNotEmpty( $source->getHashKey() );
}
}